I defined resource in XAML for SystemColors. It is working great if I set Foregroung property directly to the TextBlock. However, I am getting an error shown below if I assign foreground property in style. I am not sure what is the issue and how to solve it. Any ideas are highly appreciated!
Code when I set foreground directly in the texblock. It is working perfectly
<TextBlock Text="WindowTextColor" Foreground="{Binding WindowTextColor, Source={StaticResource SystemColors}, Converter={StaticResource colorConverter}}" />
Code when I set foreground property through the style. My app crashes:
<UserControl.Resources>
<local:ColorToBrushConverter x:Key="colorConverter" />
<local:SystemColorsWrapper x:Key="SystemColors" />
<Style x:Key="TextBlockStyle1" TargetType="TextBlock">
<Setter Property="Foreground" Value="{Binding WindowColor, Source={StaticResource SystemColors}, Converter={StaticResource colorConverter}}"/>
</Style>
</UserControl.Resources>
<Grid Background="#FFB8B8B8">
<TextBlock Text="WindowColor" Style="{StaticResource TextBlockStyle1}" />
</Grid>
The error I am getting:
System.Windows.Markup.XamlParseException occurred Message=Set property '' threw an exception. [Line: 11 Position: 41] LineNumber=11 LinePosition=41 StackTrace: at System.Windows.Application.LoadComponent(Object component, Uri resourceLocator) at SilverlightSysColors.MainPage.InitializeComponent() at SilverlightSysColors.MainPage..ctor() InnerException: System.NotSupportedException Message=Cannot set read-only property ''. StackTrace: at MS.Internal.XamlMemberInfo.SetValue(Object target, Object value) at MS.Internal.XamlManagedRuntimeRPInvokes.SetValue(XamlTypeToken inType, XamlQualifiedObject& inObj, XamlPropertyToken inProperty, XamlQualifiedObject& inValue) InnerException: