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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T08:01:09+00:00 2026-05-24T08:01:09+00:00

I created a WPF custom control, which works fine. It has a style which

  • 0

I created a WPF custom control, which works fine.
It has a style which sets some properties and a template.

Now i want to change the control, so it has a ‘Active’ property.
If this is true it should use the Property ‘ActiveBrush’ for the Stroke
of some Rectangles in the Template, else it should use ‘InactiveBrush’.

I want to use the ActiveBrush as the default Stroke, and change it to InactiveBrush
with a Trigger.

This works fine with one Rectangle when i use this:

<Trigger Property="Active" Value="False">
  <Setter TargetName="Rec1" Property="Stroke" Value="{Binding Path=InactiveBrush, RelativeSource={RelativeSource TemplatedParent}}"/>
</Trigger>

But since I don’t want to set each rectangle with a seperated setter, I am asking myself if it shouldn’t be possible to set the property of all Rectangles in the Template with one Setter.

I already tried:

<Trigger Property="Active" Value="False">
  <Setter Property="Rectangle.Stroke" Value="{Binding Path=InactiveBrush, RelativeSource={RelativeSource TemplatedParent}}"/>
</Trigger>

But this didn’t work.

Has anyone a suggestion, how to implement this?

Thanks in advance.

  • 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-24T08:01:10+00:00Added an answer on May 24, 2026 at 8:01 am

    @Robert Rossney – this style will not run since a target type of Rectangle doesn’t have a property Active. But that is the right path to go, with a minor change:

    <Style TargetType="Rectangle">
        <Style.Triggers>
            <DataTrigger Binding="{Binding Active, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:MyControl}}}" Value="False">
                <Setter Property="Stroke" Value="{Binding Path=InactiveBrush, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:MyControl}}}"/>
            </DataTrigger>
        </Style.Triggers>
    </Style>
    

    This style should be nested in Style.Resources of the control style or in ControlTemplate.Resources of the ControlTemplate for the control. This way you’re localizing this style only to your control. Any Rectangle outside of your control will not be affected.

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

Sidebar

Related Questions

I created a grid in procedural code on my WPF page. Now I want
I know how to create a custom user control in WPF but how can
I've created an attached behaviour in my WPF application which lets me handle the
I've created a simple desktop application in C# 3.0 to learn some C#, wpf
I'm trying to create a WPF Shape (PolyLine) editor, which is a control that
I am creating paint like application using WPF. Now i need to create control
I am trying to create a custom style for a WPF ComboBox but whenever
I'd like to create a custom WPF control using generics: public class MyGenericTypeControl<T> :
I am trying to use Validation in WPF. I created a NotNullOrEmptyValidationRule as shown
I'm newbie to WPF, and maybe ask some stupid question. However. I have a

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.