How can I change the value of a static WPF 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 text blocks reference
<TextBlock Grid.Row="2" Grid.Column="1" Text="{Binding Path=Breadth, StringFormat={StaticResource ResourceKey=LengthFormat}}" />
then depending on the object associated with the control, I would like to change the formats. I set the 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 line.
However this does not work, does someone suggest whynot?
Greetings
source share