Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4547166
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T16:03:21+00:00 2026-05-21T16:03:21+00:00

I defined resource in XAML for SystemColors. It is working great if I set

  • 0

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:

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T16:03:22+00:00Added an answer on May 21, 2026 at 4:03 pm

    You can’t include a binding in the a Setter. The binding is applied to the ValueProperty dependency property of the Setter which isn’t really your intention. What happens is the style is applied during Xaml parsing (before the binding can apply its value) which in turn cause the style to be sealed. When an attempt by the binding is made to adjust the value of the Setter it fails because values become read only once the style has been used.

    Edit

    A work around based on my guess that dynamic binding isn’t really that necessary you just want a convenient means of accessing the members of the SystemColors static class. My approach would be to create a derivative of ResourceDictionary to carry a complete set of resources to the SystemColors class including both a Color and a Brush for each property and named accordingly. A little bit of reflection is helpful:-

    public class SystemColorsResources : ResourceDictionary
    {
        public SystemColorsResources()
        {
            foreach (PropertyInfo pi in typeof(SystemColors).GetProperties())
            {
                Color c = (Color)pi.GetValue(null, null);
                Add(pi.Name, c);
                Add(pi.Name.Replace("Color", "Brush"), new SolidColorBrush(c));
            }
        }
    }
    

    With this class in your app include an instance of it in your MergedDictionaries list in the App.Xaml:-

    <Application.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <local:SystemColorsResources />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Application.Resources>
    

    Now you can use the system color property names with their “Brush” variants as straight forward static resources:-

    <UserControl.Resources>
      <Style x:Key="TextBlockStyle1" TargetType="TextBlock">
        <Setter Property="Foreground" Value="{StaticResource WindowBrush}" />
      </Style>
    </UserControl.Resources>
    
    <Grid Background="#FFB8B8B8">
        <TextBlock Text="WindowColor" Style="{StaticResource TextBlockStyle1}" />
    </Grid>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I Have a ResourceDictionary Generic.xaml which consists of a set of other resource dictionaries,
What is the benefit of Connectedness as defined by Resource Oriented Architecture (ROA)? The
I have a ComponentResourceKey defined in my resource dictionary like this: <Style x:Key={ComponentResourceKey TypeInTargetAssembly={x:Type
I have defined a new dialog and its controls in an already existing resource
Background: I am getting a Internal Server 500 24 50 error after deploying an
The following XAML (below) defines a custom collection in resources and attempts to populate
I defined a record named log . I want to create an mnesia table
User-Defined Functions & Collating Sequences Full support for user-defined functions and collating sequences means
I defined a Controller to force authentication by using the [Authorize] attribute. When a
NSInteger / NSUInteger are Cocoa-defined replacements for the regular built-in types. Is there any

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.