我在 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";
}
MyView.xaml(15,3): error MC3054: The type 'MyView' cannot have a Name attribute. Value types and types without a default constructor can be used as items within a ResourceDictionary.
- 那么解决方案是什么呢? - Mike Nakis