9
我想绑定到资源(DynamicResource)并访问该资源上的属性,但有没有办法做到这一点?如何绑定动态资源并指定路径
(我想在Visual Studio中的XAML编辑器构造可视化的默认值。引用过的DataContext也没有通过我的窗口类增加了一个属性的对象时,这些不能被看见......)
没有工作的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; }
}
+1,这似乎是围绕一个更清洁的工作和我”已经做到这一点效果很好 – marr75 2010-08-30 10:58:54
不要忘了接受答案,然后;) – 2010-08-30 13:45:04