[英]How to check data when using binding in WPF
Maybe this is easy, but I didn't find a solution for my problem yet. 也许这很容易,但是我还没有找到解决问题的方法。
When I use binding and a user changes for example the text in a textbox, how can I perform some backround checks like: 当我使用绑定并且用户更改了例如文本框中的文本时,如何执行一些背景检查:
Without binding this is easy i just call the functions that do the trick. 如果没有绑定,这很容易,我只需调用完成该功能的函数即可。
Example: 例:
<TextBox x:Name="textbox_Name" Height="23" Margin="108,37,20,0" TextWrapping="Wrap" Text="{Binding Name,UpdateSourceTrigger=LostFocus}" VerticalAlignment="Top"/>
Normaly I woud do something like: if(!Database.isExistingObject(textbox_Name.Text) { ObjectXYZ.Name=textbox_Name.Text; }
通常,我会做类似的事情:
if(!Database.isExistingObject(textbox_Name.Text) { ObjectXYZ.Name=textbox_Name.Text; }
With binding the name gets directly changed(Two way binding)...how can I check it before its changed? 通过绑定,名称可以直接更改(双向绑定)...如何在更改之前进行检查?
You can still call your background checks if you call them right after the user has updated the textbox content. 如果您在用户更新文本框内容之后立即调用背景检查,则仍可以调用它们。
private string name;
public string Name
{
get
{
return name;
}
set
{
CheckName(value); // Or whatever are you check functions
name = value;
PropertyChanged("Name");
}
}
I hope this helps. 我希望这有帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.