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 9088591
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T21:56:13+00:00 2026-06-16T21:56:13+00:00

I have custom control in wpf which change his look based on one Property:

  • 0

I have custom control in wpf which change his look based on one Property:

…

<Grid>
   <Rectangle Fill="[Something]" />
</Grid>

In code i have the property AlarmLevel, when AlarmLevel is bigger than 5 I want the fill to be red, otherwise blue.
How can I do this. (I don’t want the fill property to be exposed)

Tnx

  • 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-16T21:56:14+00:00Added an answer on June 16, 2026 at 9:56 pm

    Since you’re basing your fill value on an inequality, you could do this a couple of ways.

    The recommended way is probably to use a converter on your binding to make it into a boolean value. Then use a data trigger to set the fill value based on whether the value is true or false, like so:

    <Rectangle>
      <Rectangle.Style>
        <Style TargetType="Rectangle">
          <Style.Triggers>
            <DataTrigger Binding="{Binding AlarmLevel, Converter={StaticResource AlarmLevelConverter}}" Value="True">
              <Setter Property="Fill">
                <Setter.Value>
                  <SolidColorBrush Color="Red" />
                </Setter.Value>
              </Setter>
            </DataTrigger>
            <DataTrigger Binding="{Binding AlarmLevel, Converter={StaticResource AlarmLevelConverter}}" Value="False">
              <Setter Property="Fill">
                <Setter.Value>
                  <SolidColorBrush Color="Black" />
                </Setter.Value>
              </Setter>
            </DataTrigger>
          </Style.Triggers>
        </Style>
      </Rectangle.Style>
    </Rectangle>
    

    Your converter could look something like (perhaps with more exception handling):

      public class AlarmLevelConverter: IValueConverter {
    
        public object Convert(object value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture) {
          return ((int)(value) > 5);
        }
    
        public object ConvertBack(object value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture) {
          throw new NotSupportedException();
        }
      }
    

    Don’t forget you’ll need to add a reference to the converter class as a resource on your user control:

    If you wanted to forego the converter method, you could also create a “helper” boolean property in your data context called something like “IsAlarming”. It would look something like:

    public bool IsAlarming {
      get { return AlarmLevel > 5; }
    }
    

    You would then bind your data trigger to IsAlarming rather than AlarmLevel. This isn’t recommended though, because it’s not pure MVVM.

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

Sidebar

Related Questions

I have a custom WPF control which consist of single TextBox <UserControl HorizontalAlignment=Left x:Class=WPFDiagramDesignerControl.Components.UcWBSBlock
In my WPF project I have a custom control which is visually represented by
I have a custom control which is having a dependency property defined in it
I have a Custom control in WPF in which I define a large ItemsControl
I have created a custom WPF user control which is intended to be used
I have a custom WPF control base class. This base class registers a custom
In a WPF/MVVM application I have a custom control on a particular view. This
In WPF, I have a custom control that inherits from TreeView. The code is
I have a custom control which displays results of some operations. It is hidden
I have a WPF Custom Control I defined in a WPF Control Library project

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.