Reputation: 38336
I have the following problem: I want to access one of these three vars, defined in XAML Resource
<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="../../Themes/MainStyle.xaml" />
</ResourceDictionary.MergedDictionaries>
<System:Int32 x:Key="maxVal">500</System:Int32>
<System:Int32 x:Key="minVal">250</System:Int32>
<System:Int32 x:Key="actualWidth">250</System:Int32>
</ResourceDictionary>
</UserControl.Resources>
I want to access the value of "actualWidth" from Codebehind file like this:
private void MinMaxGraphicsMessageSink(bool minmax)
{
actualWidth = minmax ? 900 : 300;
}
But this doesn't work. Can someone help?
Upvotes: 1
Views: 5433
Reputation: 30097
int maxVal = (Convert.ToInt32(FindResource("maxVal")));
similarly min value
int minVal = (Convert.ToInt32(FindResource("minVal")));
to set value of a resource you can do like this
var resourceDictionary = this.Resources;
resourceDictionary["actualWidth"] = somevalue;
Upvotes: 5
Reputation: 14940
I think you can use
var max = (int)Application.Resources["maxValue"];
or something similar.
Upvotes: 0