Reputation: 5664
I have defined a custom SolidColorBrush in my app.xaml
<Application.Resources>
<SolidColorBrush x:Key="App_DarkForeground" Color="White"/>
</Application.Resources>
in my page1.xaml, i am using above brush as
<TextBlock x:Name="lblTileColor" Text="user color:" Foreground="{StaticResource App_DarkForeground}"/>
I am trying to change the color of this brush at run time based on user event in c#.
I am using below piece to set the color but i am hitting with this exception.
Application.Current.Resources["App_DarkForeground"] = new SolidColorBrush(Color.FromArgb(0xff, 255, 122, 255));
Here is the exception details:
An exception of type 'System.NotImplementedException' occurred in System.Windows.ni.dll but was not handled in user code
i followed this question but no luck.
Upvotes: 0
Views: 322
Reputation: 7135
The question you linked was talking about how its done in WPF not windows phone. Apparently, for windows phone you cannot set resource dictionary values.
Why not just assign the foreground property in code?
lblTileColor.Foreground = new SolidColorBrush(Color.FromArgb(0xff, 255, 122, 255));
Or if you are using MVVM you can just bind it:
<TextBlock x:Name="lblTileColor" Text="user color:" Foreground="{Binding ForegroundProperty"} />
Upvotes: 1