Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

WPF issue with Trigger

Posted on 2016-10-09
2
114 Views
Last Modified: 2016-10-25
I am trying to add a Trigger to a control template (for a button) and I am getting an error that says the target cannot be found. Here is a code snippet:

                <ControlTemplate TargetType="Button">
                    <Border x:Name="t"
                            Margin="{TemplateBinding Margin}"
                            BorderBrush="{TemplateBinding BorderBrush}"
                            BorderThickness="{TemplateBinding BorderThickness}">
                        <Border.Background>
                            <LinearGradientBrush StartPoint="0,0"
                                                 EndPoint="0,1">
                                <LinearGradientBrush.GradientStops>
                                    <GradientStop x:Name="BackgroundGradientStop1"
                                                  Offset="0"
                                                  Color="{StaticResource BackgroundColor1}" />
                                    <GradientStop x:Name="BackgroundGradientStop2"
                                                  Offset="1"
                                                  Color="{StaticResource BackgroundColor2}" />
                                </LinearGradientBrush.GradientStops>
                            </LinearGradientBrush>
                        </Border.Background>

                        <ContentPresenter Margin="{TemplateBinding Padding}" />
                    </Border>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsEnabled"
                                 Value="False">
                            <Setter TargetName="BackgroundGradientStop1"
                                    Property="Color"
                                    Value="White" />
                        </Trigger>

Open in new window


The name "BackgroundGradientStop1" in the Setter of the Trigger is reported as not found, however it is defined before that in the code just above. The same target name is used in MultiTriggers after this one and no error is reported.

What is wrong with my code?
Sid
0
Comment
Question by:Sid Price
2 Comments
 

Accepted Solution

by:
Sid Price earned 0 total points
ID: 41859217
I have discovered the issue with the above code from another source, The "BackgroundGradientStop1" element is NOT derived from FrameworkElement and therefore cannot be the target of a Setter.
Sid
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
Because your company can’t afford for you to make SEO mistakes, you’ll want to ensure you’re taking the right steps each and every time you post a new piece of content. This list of optimization do’s and don’ts can help you become an SEO wizard.
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question