データ バインディングに関するオンライン ドキュメントを読みましたが、それでも機能しませんでした。私は単にデータバインディングを理解し、本来あるべき方法で物事を行いたいだけです。
これが私のUI.xaml.csのコードです
namespace mynamespace
{
class Customer
{
private string _name = "TEST";
public string Name
{
get { return this._name; }
set { this._name = value; }
}
}
public partial class UI: UserControl
{
public UI()
{
InitializeComponent();
Customer c = new Customer();
this.DataContext = c;
}
}
}
バインディング コード (ターゲットはテキスト ボックス) は次のようになります。
<TextBox Name="MyTextBox" Text="{Binding Path=Name}" />
テキストボックスに TEST と表示されるはずですが、そうではありません。テキストボックスには何もありません。ドキュメント (Data Binding Overview、Binding Declarations Overview、および Binding Sources Overview) は、私にはあまり明確ではありません。
これは、出力ウィンドウからのエラー メッセージです。
BindingExpression path error: 'Name' property not found on 'object' ''ConfigurationSettings' (HashCode=36012562)'. BindingExpression:Path=Name; DataItem='ConfigurationSettings' (HashCode=36012562); target element is 'TextBox' (Name='MyTextBox'); target property is 'Text' (type 'String')