リソース (DynamicResource) にバインドし、そのリソースのプロパティにアクセスしたいのですが、それを行う方法はありますか?
(Visual Studio の xaml エディターでコンストラクターからの既定値を視覚化したいと考えています。これらは、DataContext を介してオブジェクトを参照したり、Window クラスに追加されたプロパティを介して参照したりするときに表示されません...)
xaml が動作しない: (composer では動作しますが、実行時には動作しません...)
<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; }
}