How can i change the value of a WPF static resource at runtime?
I have the following resources
<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> which some textblocks reference
<TextBlock Grid.Row="2" Grid.Column="1" Text="{Binding Path=Breadth, StringFormat={StaticResource ResourceKey=LengthFormat}}" /> then depending on the object to be bound to the control i would like to change the formats. I have set up properties in the control as follows:
public string LengthFormat { set { this.Resources["LengthFormat"] = value; } } public string AreaFormat { set { this.Resources["AreaFormat"] = value; } } public string InertiaFormat { set { this.Resources["InertiaFormat"] = value; } } then before binding i set each string.
However it doesn't work, anyone suggest whynot?
Cheers