WPF-通过DataContext绑定 [英] WPF - binding via DataContext
问题描述
我是WPF的一名新手.
我正在尝试绑定.
基本上,我在XAML文件的构造函数中设置了DataContext.
基本上,我创建一个.xaml表单,并通过在< textbox>之间添加以下内容来设置XAML中的Textbox绑定.标签:
Text ="{Binding Path = someProperty}"
加载表单时,在文本框中看到"someProperty"的值.
没问题.
如果"someProperty"不存在,则不会标记任何错误.
如果找不到该属性,是否有生成错误的方法?
I am a complete newbie to WPF.
I am experimenting with binding.
Basically I set the DataContext in the constructor of the XAML file
Basically I create a .xaml form and set a Textbox binding in XAML by adding the following between the <textbox> tag:
Text="{Binding Path=someProperty}"
When I load the form up, I see the value of "someProperty" in the textbox.
No problem.
If "someProperty" doesn''t exist, no error is flagged.
Is there a way to generate an error if the property cannot be found?
推荐答案
数据绑定错误将像输出"窗口中的警告一样引发.您可以在Visual Studio中打开输出"窗口,然后检查错误.
此处 [ XAML DataBinding中的调试技巧 [ ^ ]
如果有帮助,请将其标记为答案"
The Data Binding errors will be thrown like warning in the Output Window. You can open the Output Window in Visual Studio and check the error.
Here[^] is another example to listen these error.
or you can try Debugging Trick in XAML DataBinding[^] too
Mark it as Answer if it is helpful
您可以通过绑定来控制验证-请参见 ^ ].
You can control validations with binding - see here[^].
这篇关于WPF-通过DataContext绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!