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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T17:18:23+00:00 2026-05-12T17:18:23+00:00

I have a label control where I use a converter to switch its styles

  • 0

I have a label control where I use a converter to switch its styles based on a bool property, IsCheckedOut on my viewmodel, like so:

    <UserControl.Resources>
      <Converters:BooleanStyleConverter 
       x:Key="BooleanStyleConverter " 
       StyleFalse="{StaticResource HeaderLabelStyle}" 
       StyleTrue="{StaticResource HeaderLabelHighlightedStyle}" />
     </UserControl.Resources>

    <Label Style="{Binding Path=IsCheckedOut, 
Converter={StaticResource BooleanStyleConverter}}">
    some content here
    </Label>

The converter simply returns one of the two styles:

public class BooleanStyleConverter : IValueConverter 
    {
        public Style StyleFalse { get; set; }
        public Style StyleTrue { get; set; }
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if ((bool)value)
            {
                return StyleTrue;
            }
            return StyleFalse;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }

And the styles look something like this:

<Style x:Key="HeaderLabelHighlightedStyle" TargetType="{x:Type Label}">
 <Setter Property="Template">
  <Setter.Value>
   <ControlTemplate TargetType="Label">
    <Border Background="{StaticResource RedGradient}">
     <ContentPresenter />
    </Border>
   </ControlTemplate>
  </Setter.Value>
 </Setter>
</Style>

<Style x:Key="HeaderLabelHighlightedStyle" TargetType="{x:Type Label}">
 <Setter Property="Template">
  <Setter.Value>
   <ControlTemplate TargetType="Label">
    <Border Background="{StaticResource BlueGradient}">
     <ContentPresenter />
    </Border>
   </ControlTemplate>
  </Setter.Value>
 </Setter>
</Style>

So when IsCheckedOut is true the label gets a red background, and when it’s false it gets a blue background (well, the styles are a bit more complicated, but you get the idea).
Now, I’d like to have a transition between the styles, so that the new colors fade in when IsCheckedOut changes.
Does anyone know how I can accomplish 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-12T17:18:24+00:00Added an answer on May 12, 2026 at 5:18 pm

    Sorry, but you’re doing it wrong.

    You do get bonus points for being extremely creative and ambitious in your solution. But you’ve taken the proverbial 5kg hammer down on a thumbtack.

    The correct solution in this situation is to use Storyboards nested in VSM States.
    It looks like you essentially have 2 States for your UI: One where some business logic value is true and another state for when it’s false. Note that the aforementioned distinction is 100% technology independent. In any technology, whatever it is you’re trying to achieve would be considered 2 states for your UI.

    In Silverlight/WPF, instead of hacking together something that mimics UI states, you could actually create VisualStateManager states.

    Technically it would work in the following way:
    1. Your UserControl would have 1 VisualStateGroup that has 2 VisualStates (one for true and another for false).
    2. Those VSM states each represent 1 storyboard.
    3. That storyboard would change the template or any other properties you feel are appropriate.

    To learn the basics of VSM I strongly suggest you spend the next 30 minutes watching the following VSM videos: http://expression.microsoft.com/en-us/cc643423.aspx (Under “How Do I?”)
    Seriously, these videos are phenomenally successful in explaining VSM. The one that most pertinent to your dilemma is “Add States to a Control” but I’ll suggest you watch all of them.

    In WPF, you could use the VisualStateManager from the WPF Toolkit.

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

Sidebar

Related Questions

I've got a treeview control, and have caught its after-label-edit event. I want to
I have this label control in my web page <asp:Label ID=Label1 runat=server Text=test></asp:Label> And
I have a composite control that adds a TextBox and a Label control to
I have a label function like : private function formatDate (item:Object, column:DataGridColumn):String { var
I've got a multiline textBox that I would like to have a label on
I have a section: \section{Introduction} \label{sec:introduction} I'd like a link to the section where
i have a label in my form, and im trying to get the value
Here's the situation: I have a label's text set, immediately followed by a response.redirect()
I have small page which has label, DropDownList and a submit button. <div> <asp:label
I've binded the tooltip of a slider control to it's Value property and i'm

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.