さて、これは簡単なことになると思いましたが、明らかにそうではありません(私はXAML / WPFの初心者です、ところで)
Window1とEditCustomObjectWindowの2つのWPFウィンドウがあります。後者は、Window1によって提供されるCustomObjectインスタンスを編集するために必要です。(私はこの問題に関係のない多くのコードを省略しました)
Window1.xaml.cs:
// first window, holding an instance of CustomObject
public partial class Window1 : Window {
public CustomObject CustomObject {
get;
set;
}
void buttonClicked(object sender, RoutedEventArgs e) {
new Windows(CustomObject).ShowDialog();
}
}
EditCustomObjectWindow.xaml.cs:
public partial class EditCustomObjectWindow : Window {
public CustomObject CustomObject {
get;
set;
}
public EditCustomObjectWindow (CustomObject customObject) {
this.CustomObject = customObject;
}
}
EditCustomObjectWindow.xaml:
<TextBox
Height="22"
Margin="5"
Width="150"
Text="{Binding Path=CustomObject.SomeProperty, Mode=TwoWay, PresentationTraceSources.TraceLevel=High}"></TextBox>
もちろん、CustomObjectにはSomePropertyのパブリックアクセサーがあります。ボタンをクリックすると、次の情報が出力ウィンドウにトレースされます。しかし、どういうわけか、私はそれを問題の原因に翻訳することができません。
System.Windows.Data Warning: 54 : Created BindingExpression (hash=31654880) for Binding (hash=40799911)
System.Windows.Data Warning: 56 : Path: 'CustomObject.SomeProperty' System.Windows.Data Warning: 59 : BindingExpression (hash=31654880): Default update trigger resolved to LostFocus
System.Windows.Data Warning: 60 : BindingExpression (hash=31654880): Attach to
System.Windows.Controls.TextBox.Text (hash=58067579)
System.Windows.Data Warning: 65 : BindingExpression (hash=31654880): Resolving source
System.Windows.Data Warning: 68 : BindingExpression (hash=31654880): Found data context element: TextBox (hash=58067579) (OK)
System.Windows.Data Warning: 69 : BindingExpression (hash=31654880): DataContext is null
System.Windows.Data Warning: 63 : BindingExpression (hash=31654880): Resolve source deferred
System.Windows.Data Warning: 65 : BindingExpression (hash=31654880): Resolving source
System.Windows.Data Warning: 68 : BindingExpression (hash=31654880): Found data context element: TextBox (hash=58067579) (OK)
System.Windows.Data Warning: 69 : BindingExpression (hash=31654880): DataContext is null
System.Windows.Data Warning: 65 : BindingExpression (hash=31654880): Resolving source
System.Windows.Data Warning: 68 : BindingExpression (hash=31654880): Found data context element: TextBox (hash=58067579) (OK)
System.Windows.Data Warning: 69 : BindingExpression (hash=31654880): DataContext is null
System.Windows.Data Warning: 65 : BindingExpression (hash=31654880): Resolving source
System.Windows.Data Warning: 68 : BindingExpression (hash=31654880): Found data context element: TextBox (hash=58067579) (OK)
System.Windows.Data Warning: 69 : BindingExpression (hash=31654880): DataContext is null
System.Windows.Data Warning: 65 : BindingExpression (hash=31654880): Resolving source (last chance)
System.Windows.Data Warning: 68 : BindingExpression (hash=31654880): Found data context element: TextBox (hash=58067579) (OK)
System.Windows.Data Warning: 76 : BindingExpression (hash=31654880): Activate with root item <null>
System.Windows.Data Warning: 104 : BindingExpression (hash=31654880): Item at level 0 is null - no accessor
System.Windows.Data Warning: 101 : BindingExpression (hash=31654880): Replace item at level 1 with {NullDataItem}
System.Windows.Data Warning: 78 : BindingExpression (hash=31654880): TransferValue - got raw value {DependencyProperty.UnsetValue}
System.Windows.Data Warning: 86 : BindingExpression (hash=31654880): TransferValue - using fallback/default value ''
System.Windows.Data Warning: 87 : BindingExpression (hash=31654880): TransferValue - using final value ''