0
我正在对WPF项目进行一些更改以减少弃用。 我试图做的一件事是将我的Textbox.Text
值绑定到一个简单的类,如下所示。我用的是立即窗口中显示名称的值WPF - 将文本框文本绑定到类属性
<TextBox x:Name="txtNCM"
Grid.Column="1"
Margin="5"
MaxLength="8"
Text="{Binding Path=Name}"
</TextBox>
public partial class wCad_NCM : UserControl, INotifyPropertyChanged
{
private string name;
public event PropertyChangedEventHandler PropertyChanged;
public string Name
{
get { return name; }
set
{
name = value;
OnPropertyChanged("Name");
}
}
protected void OnPropertyChanged(string name)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (handler != null)
{
handler(this, new PropertyChangedEventArgs(name));
}
}
public wCad_NCM()
{
InitializeComponent();
}
}
每次,它显示为空。我真的很新的这一点,所以我不得不寻找类似的情况相适应,但我不知道如何使这项工作:(
你是最好的,它的工作。谢谢 ;) –