wpf命令而不是事件 [英] wpf command instead of event
问题描述
hi guys
如何用ICommand替换下一个事件
private void textBox1_TextChanged(object sender,TextChangedEventArgs e)
{
textBox2.Text = textBox1.Text;
}
没有人告诉我使用绑定cuz textBox1和2已绑定到类属性。
任何帮助将不胜感激
wpf,c#,VS2017
假设Textbox1绑定到text1,textbox2绑定到text2。
使这些都成为propfull。
在text1的setter中,你可以将text2设置为值,以及text1的后备成员。
这不区分将text1设置为其他地方用户输入。
你可以通过添加公共方法来设置text1支持成员并在text1上更改属性。
或
您可以使用mvvmlight eventtocommand。
大致相似:
https://stackoverflow.com/questions / 5868589 / mvvm-light-adding-eventtocommand-in-xaml-without-blend-easy-way-or--ipippet
hi guys
how can i replace the next event with ICommand
private void textBox1_TextChanged(object sender, TextChangedEventArgs e) { textBox2.Text = textBox1.Text; }
no one tell me to use binding cuz textBox1 and 2 already binded to a class property.
any help will be appreciated
wpf , c#, VS2017
Say Textbox1 is bound to text1 and textbox2 is bound to text2.
Make these both propfull.
In the setter of text1 you could set text2 to the value, as well as the backing member of text1.
That doesn't differentiate between setting text1 from somewhere other than user input.
You could get round that by adding a public method sets the text1 backing member and raises property changed on text1.
Or
You could use mvvmlight eventtocommand.
Roughly like:
https://stackoverflow.com/questions/5868589/mvvm-light-adding-eventtocommand-in-xaml-without-blend-easier-way-or-snippet
这篇关于wpf命令而不是事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!