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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T20:38:27+00:00 2026-06-08T20:38:27+00:00

I have defined a dependency property that uses an enum to update the background

  • 0

I have defined a dependency property that uses an enum to update the background colour of a button. When it runs I get a “Default value type does not match type of property ‘CurrentWarningLevel'” exception. The dependency property is as follows:

public enum WarningLevels
{
    wlError=0,
    wlWarning,
    wlInfo
};

public class WarningLevelButton : Button
{
    static WarningLevelButton()
    {
    }

    public WarningLevels CurrentWarningLevel
    {
        get { return (WarningLevels)GetValue(WarningLevelProperty); }
        set { base.SetValue(WarningLevelProperty, value); }
    }

    public static readonly DependencyProperty WarningLevelProperty =
      DependencyProperty.Register("CurrentWarningLevel", typeof(WarningLevels), typeof(WarningLevelButton), new PropertyMetadata(false));
}

I am trying to use the property as follows:

<Trigger Property="local:WarningLevelButton.CurrentWarningLevel" Value="wlError">
    <Setter TargetName="ButtonBody" Property="Background" Value="{StaticResource CtlRedBrush}" />
    <Setter TargetName="ButtonBody" Property="BorderBrush" Value="{StaticResource CtlRedBrush}" />
</Trigger>
<Trigger Property="local:WarningLevelButton.CurrentWarningLevel" Value="wlWarning">
    <Setter TargetName="ButtonBody" Property="Background" Value="{StaticResource GreyGradientBrush}" />
    <Setter TargetName="ButtonBody" Property="BorderBrush" Value="{StaticResource BorderBrush}" />
</Trigger>
  • 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-08T20:38:29+00:00Added an answer on June 8, 2026 at 8:38 pm

    1)
    Because you can’t cast false(bool) into WarningLevels.

    Remember the first parameter of PropertyMetadata is your default value.

    2) You propably will run into another problem. Your Trigger value

    Value="wlError"
    

    is a string, which can’t be converted into an enum aswell, without a type converter. The easiest way to fix that is to extend your value:

    <Trigger Property="local:WarningLevelButton.CurrentWarningLevel" >
        <Trigger.Value>
            <my:WarningLevels>wlError</my:WarningLevels>
        </Trigger.Value>
        <Setter TargetName="ButtonBody" Property="Background" Value="{StaticResource CtlRedBrush}" />
        <Setter TargetName="ButtonBody" Property="BorderBrush" Value="{StaticResource CtlRedBrush}" />
    </Trigger>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a rather simple user control (RatingControl) that has a dependency property defined
I have 2 controls A and B that need to share a dependency property.
I have a custom Dependency Property defined like so: public static readonly DependencyProperty MyDependencyProperty
Assuming I have an attached property defined like that : public static string GetMyProperty(DependencyObject
I have defined a ConfigurationProperty class, which is basicly a key-value pair (with key
I have defined CSS in MasterPage so that all pages can use the same
I have added the dependency property MyList to a wpf textbox. The dependency property
I have a user control that has a grid (the one you get automatically
I have the following simple custom control that I have defined for a Windows
I have defined a dependency propery as follows: public static readonly DependencyProperty AnimateColumnWidthProperty =

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.