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

  • SEARCH
  • Home
  • 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 9006545
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T01:26:22+00:00 2026-06-16T01:26:22+00:00

[EDIT] *I had forgotten to include the Exception returned ‘System.Windows.Style’ is not a valid

  • 0

[EDIT] *I had forgotten to include the Exception returned

'System.Windows.Style' is not a valid value for property 'Fill'*

This is my first post, I’ve already done lots of searching for questions where this might have already been answered to no success. I’m a complete noob when it comes to MVVM, Prism, and WPF and I have been thrown in the deep end on this one.

I wish to change the contents of 2 rectangles depending on a boolean in the Model (Binding Passed).

if a test returns Pass (bool True) then we display colour Green for first rectangle, and the second rectangle will display the UserControl.Resource Style x:Key=”RectanglePass”.
If test fails, then first rectangle is red, and second displays UserControl.Resource Style x:Key=”RectangleFail”

I have the following xaml code:

<UserControl x:Class="Integration.Memjet.Aoqc.Views.ProcessResultView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300">

 <UserControl.Resources>
    <Style x:Key="RectangleFail" TargetType="Rectangle">
        <Setter Property="Fill">
            <Setter.Value>
                <VisualBrush>
                    ....
                </VisualBrush>
            </Setter.Value>
        </Setter>
    </Style>
    <Style x:Key="RectanglePass" TargetType="Rectangle">
        <Setter Property="Fill">
            <Setter.Value>
                <VisualBrush>
                    ....
                </VisualBrush>
            </Setter.Value>
        </Setter>
    </Style>
</UserControl.Resources>
<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="60"></RowDefinition>
        <RowDefinition Height="60"></RowDefinition>
        <RowDefinition></RowDefinition>
    </Grid.RowDefinitions>
    <Label VerticalAlignment="Center" HorizontalAlignment="Center" FontSize="20">PASS</Label>
    <Rectangle Name="rectStatus" Grid.Row="1">
        <Rectangle.Style>
            <Style TargetType="{x:Type Rectangle}">
                <Style.Triggers>
                    <DataTrigger Binding="{Binding Passed}" Value="True">
                        <Setter Property="Fill" Value="Green" />
                    </DataTrigger>
                    <DataTrigger Binding="{Binding Passed}" Value="False">
                        <Setter Property="Fill" Value="Red" />
                    </DataTrigger>
                </Style.Triggers>
            </Style>
        </Rectangle.Style>
    </Rectangle>

    <Rectangle Name="rectStatusImg" Width="120" Height="120" Grid.Row="2" >
        <Rectangle.Style>
            <Style TargetType="{x:Type Rectangle}">
                <Style.Triggers>
                    <DataTrigger Binding="{Binding Passed}" Value="True">
                        <Setter Property="Fill" Value="{StaticResource RectanglePass}" />
                    </DataTrigger>
                    <DataTrigger Binding="{Binding Passed}" Value="False">
                        <Setter Property="Fill" Value="{StaticResource RectangleFail}" />
                    </DataTrigger>
                </Style.Triggers>
            </Style>
        </Rectangle.Style>
    </Rectangle>
</Grid>
</UserControl>

The above doesn’t work and returns an exception.
If I was to replace the second Rectangle tag (rectStatusImg) with this line;

<Rectangle Name="rectStatusImg" Style="{StaticResource RectanglePass}" Width="120" Height="120" Grid.Row="2" ></Rectangle>

the xaml works and produces the expected result! But I wish to bind it to the Boolean Passed so I can change it programmatically.

I really hope I was able to explain my problem here.

Thank you for your help in advance, this site has always been a treasure and a great help.

Cheers,
Simon

  • 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-06-16T01:26:23+00:00Added an answer on June 16, 2026 at 1:26 am

    define two visual brushes in your resource and create a style of rectangle with data trigger like

      <VisualBrush x:Key="FailBrush">Black</VisualBrush>
        <VisualBrush x:Key="PassBrush">Red</VisualBrush>
    
        <Style x:Key="ColorRectangleStyle" TargetType="Rectangle">
            <Setter Property="Fill" Value="{StaticResource FailBrush}"/>
            <Style.Triggers>
                <DataTrigger Binding="{Binding Passed}" Value="False">
                    <Setter Property="Fill" Value="{StaticResource PassBrush}"/>
                </DataTrigger>
            </Style.Triggers>
        </Style>
    

    and use it in rectangle like

    <Rectangle Name="rectStatusImg" Width="120" Height="120" Grid.Row="2" Style="{StaticResource ColorRectangleStyle}" />
    

    Hope it helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Edit: oops. These JDBC statements work; I had forgotten to commit in SQL Plus.
Edit: JSON not complete, had to cut some Somehow one Entity has EntityState Added
EDIT: Solved it! I made stupid mistake, I had a textureId I'd forgotten about
EDIT: I had hex value(string) that i converted to a Brush hence it did
EDIT: I had hex value(string) that i converted to a Brush hence it did
EDIT: I had made a mistake during the debugging session that lead me to
Answer solved in edit below I had this piece of code Dictionary<Merchant, int> remaingCards
I posted another one on this,, but i had to edit it really much...
Edit: Turns out I just had some values -switched-. I'm working with OpenGL and
EDIT: My mistake was that I had a go after the first select statement

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.