【发布时间】:2012-01-24 17:07:21
【问题描述】:
我在 WPF 上有两个控件
<Button HorizontalAlignment="Center"
Name="btnChange"
Click="btnChange_Click"
Content="Click Me" />
<Label Name="lblCompanyId"
HorizontalAlignment="Center"
DataContext="{Binding ElementName=_this}"
Content="{Binding Path=CompanyName}" />
我们可以看到标签绑定到本地属性(在后面的代码中),当我单击按钮时,我看不到标签上的任何值...
下面是我的代码...
public static readonly DependencyProperty CompanyNameProperty =
DependencyProperty.Register("CompanyName", typeof(string), typeof(Window3), new UIPropertyMetadata(string.Empty));
public string CompanyName {
get { return (string)this.GetValue(CompanyNameProperty); }
set { this.SetValue(CompanyNameProperty, value); }
}
private void btnChange_Click(object sender, RoutedEventArgs e) {
this.CompanyName = "This is new company from code beind";
}
【问题讨论】:
标签: wpf binding properties local