実行時にWPF静的リソースの値を変更するにはどうすればよいですか?wpf静的リソースの値を変更
私はいくつかのテキストブロックは、私は形式を変更したいコントロールにバインドするオブジェクトに応じて、その後、
<TextBlock Grid.Row="2" Grid.Column="1"
Text="{Binding Path=Breadth, StringFormat={StaticResource ResourceKey=LengthFormat}}" />
を参照する次のリソース
<UserControl.Resources>
<sys:String x:Key="LengthFormat">#.# mm</sys:String>
<sys:String x:Key="AreaFormat">#.# mm²</sys:String>
<sys:String x:Key="InertiaFormat">#.# mm⁴</sys:String>
</UserControl.Resources>
を持っています。 次のように私は、コントロールのプロパティを設定している:
public string LengthFormat
{
set
{
this.Resources["LengthFormat"] = value;
}
}
public string AreaFormat
{
set
{
this.Resources["AreaFormat"] = value;
}
}
public string InertiaFormat
{
set
{
this.Resources["InertiaFormat"] = value;
}
}
その後、私は、各文字列を設定バインドする前に。
しかし、それは動作しません、誰でもお勧めですか?
乾杯
エラー4「DynamicResourceExtension」は、「バインディング」タイプの「StringFormat」プロパティで設定できません。 「DynamicResourceExtension」は、DependencyObjectのDependencyPropertyでのみ設定できます。 –
オハイオ州右、意味をなさない。この場合、私のソリューションを適用することはできません。これはDependencyPropertyに対してのみ機能します –