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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T21:16:52+00:00 2026-05-30T21:16:52+00:00

I am writing a custom user control, called MyUserControl. I have many DependecyProperties for

  • 0

I am writing a custom user control, called MyUserControl. I have many DependecyProperties for it, which I use in the MainWindow where several MyUserControl are defined multiple times. What I would like to know is how can I create custom Properties that the Triggers/Properties for a style would fire?

For example, if I have a custom property BOOL IsGoing and a custom property MyBackgroung(the background of the UserControl), both defined as :

public bool IsGoing
    {
        get { return (bool)this.GetValue(IsGoingProperty); }
        set { this.SetValue(IsGoingProperty, value); }
    }
    public static readonly DependencyProperty IsGoingProperty = DependencyProperty.RegisterAttached(
        "IsGoing", typeof(bool), typeof(MyUserControl), new PropertyMetadata(false));  

public Brush MyBackground
    {
        get { return (Brush)this.GetValue(MyBackgroundProperty); }
        set { this.SetValue(MyBackgroundProperty, value); }
    }
    public static readonly DependencyProperty MyBackgroundProperty = DependencyProperty.Register(
            "MyBackground", typeof(Brush), typeof(MyUserControl), new PropertyMetadata(Brushes.Red));

and if I define my UserControl in MainWindow.xaml, how can I access the Triggers and set MyBackground, depending on whether or not the IsGoing property is true/false?
I tried many things, but in essence, I’m trying to achieve something like:

<custom:MyUserControl MyBackground="Green" x:Name="myUC1" Margin="120.433,0,0,65.5" Height="50" Width="250" VerticalAlignment="Bottom" HorizontalAlignment="Left"  >
        <Style>
            <Style.Triggers>
                <Trigger Property="IsGoing" Value="True">
                    <Setter Property="MyBackground" Value="Yellow"/>
                </Trigger>
            </Style.Triggers>
        </Style>
    </custom:MyUserControl>

I hope my explanation is good enough for you to understand. I’ve been working on this for a couple of days now, and I can’t seem to find the solution.
Thanks for the help!!!

Adrian

  • 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-30T21:16:53+00:00Added an answer on May 30, 2026 at 9:16 pm

    Your style should just need to be used as UserControl.Style and have the correct TargetType, also default values you intend to change via trigger need to be moved into the style due to precedence:

    <custom:MyUserControl.Style>
        <Style TargetType="custom:MyUserControl">
            <Setter Property="MyBackground" Value="Green"/>
            <Style.Triggers>
                <Trigger Property="IsGoing" Value="True">
                    <Setter Property="MyBackground" Value="Yellow"/>
                </Trigger>
            </Style.Triggers>
        </Style>
    </custom:MyUserControl.Style>
    

    Whether this actually does anything depends on how you use the properties in the control definition.

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

Sidebar

Related Questions

I'm writing a plug-in for a program where I have a custom user control
I have a Windows form which hosts a custom User Control. This User Control
I have a custom WPF control which consist of single TextBox <UserControl HorizontalAlignment=Left x:Class=WPFDiagramDesignerControl.Components.UcWBSBlock
Working in WPF, writing a custom user control. I am trying to change the
I'm writing a custom user control for my asp.net site, for storing datetimes. It
Which approach should I prefer when it comes to writing a custom control in
I am writing an application that can potentially have hundreds of custom user controls
I'm writing a custom control which includes a text box input and an unordered
I'm writing a custom file selection component. In my UI, first the user clicks
I am writing a CSV exporter in Java that should respect the user's custom

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.