【发布时间】:2011-04-05 16:13:11
【问题描述】:
我想绑定到一个资源 (DynamicResource) 并访问该资源的属性,但有没有办法做到这一点?
(我想在 Visual Studio 的 xaml 编辑器中可视化来自构造函数的默认值。通过 DataContext 或通过我的 Window 类上添加的属性引用对象时看不到这些值...)
不工作 xaml:(在作曲家工作但在运行时不工作...)
<Window ... >
<Window.Resources>
<local:MyClass x:Key="myResource" />
</Window.Resources>
<StackPanel>
<Button Content="{Binding Source={DynamicResource myResource} Path=Property1}" />
<Button Content="{Binding Source={DynamicResource myResource} Path=Property2}" />
</StackPanel>
</Window>
与类(可能需要实现 INotifyPropertyChanged):
public class MyClass
{
public MyClass()
{
this.Property1 = "Ok";
this.Property2 = "Cancel";
}
public string Property1 { get; set; }
public string Property2 { get; set; }
}
【问题讨论】:
标签: visual-studio xaml binding dynamicresource