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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:47:54+00:00 2026-05-25T15:47:54+00:00

I have object with 3 property: CouldBeWhite bool CouldBeGreen bool CouldBeRed bool If CouldBeWhite

  • 0

I have object with 3 property:

CouldBeWhite bool
CouldBeGreen bool
CouldBeRed bool

    If CouldBeWhite is true, then foreground of row should be white,  if
    CouldBeGreen is true, and CouldBeWhite is false, then row should be
    Green If CouldBeRed is true, and  and CouldBeWhite is false and
    CouldBeGreen is false then row should be Red In other case row
    should be blue.

My idea now is to have some new property at viewmodel Color, when I would count color of row.

Or maybe there is some nicer way to implement this?

  • 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-25T15:47:55+00:00Added an answer on May 25, 2026 at 3:47 pm

    Add this enum to your project:-

    public enum RowState
    {
         Blue,
         Red,
         Green,
         White
    }
    

    Then add this property to your ViewModel:-

    private RowState _RowState;
    public RowState RowState
    {
         get { return _RowState; }
         set
         {
             if (value != _RowState)
             {
                   _RowState = value;
                   NotifyPropertyChanged("RowState"); // Assumes typical implementation of INotifyPropertyChanged 
             }
         }
    }
    
    private void UpdateRowState()
    {
        if (CouldBeWhite)
             RowState = RowState.White;
        else if (CouldBeGreen)
             RowState = RowState.Green;
        else if (CouldBeRed)
             RowState = RowState.Red;
        else
             RowState = RowState.Blue;
    }
    

    Call UpdateRowState when every the CouldBeXXX properties change.

    Consider that you are probably not making the foreground white or red or green just as a whim. There will be be some reason why its white, red or green. So in your code think of a simple short name to represent those reasons and replace the color names with those more meaningful names.

    Now go fetch the code for StringToValueConverter in this blog. Add an instance of this to your Xaml in the UserControl.Resources:

             <local:StringToObjectConverter x:Key="RowStateToBrush">
                 <ResourceDictionary>
                     <SolidColorBrush Color="Red" x:Key="Red" />
                     <SolidColorBrush Color="Green" x:Key="Green" />
                     <SolidColorBrush Color="White" x:Key="White" />
                     <SolidColorBrush Color="Blue" x:Key="__default__" /> 
                </ResourceDictionary>
             </local:StringToObjectConverter>
    

    You can bind on a TextBlock:

      <TextBlock Text="{Binding SomeTextProperty}"  Foreground="{Binding RowState, Converter={StaticResource RowStateToBrush}}" />
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have object A which in turn has a property of type Object B
I have an object with a Property of type byte[ , ,*] now i'd
I have an object with a property called name. This object has a sub
I have a class: class MyClass(object): @property def myproperty(self): return 'hello' Using mox and
I have a GridView where one column is bound to an object property containing
I have a c# object with a property called Gender which is declared as
I have an object with a NameValueCollection property which I'm managing with Linq2SQL. I
I have an object with a string[] property. When I assign this as the
I have persistent object, with a string property that often is over 500 charachters.
I have a object (product), with a property of type 'array' e.g. product.tags =

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.