我正在尝试使用以下命令将文本框绑定到 .cs 文件中定义的字符串:
Xml代码:
<TextBox x:Name="textBox_Data" CaretBrush="DodgerBlue" Foreground="White" Text="{Binding Data}" HorizontalAlignment="Left" Height="22" Margin="10,10,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="123" SelectionChanged="textBox_Data_SelectionChanged"/>
Xaml.cs 代码:
public string Data{get; set;}
但是字符串没有更新......
你的类必须派生自INotifyPropertyChanged
,你必须在你的属性设置器中实现它
或者更愉快的方式:PropertyChanged.Fody
从nuget安装。您可以在此处阅读更多相关信息:https : //github.com/Fody/PropertyChanged
请记住,不要this.DataContext=this;
在初始化窗口时使用,按照dovid建议使用绑定。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句