Solved

WPF issue with Trigger

Posted on 2016-10-09
2
108 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
There’s a good reason for why it’s called a homepage – it closely resembles that of a physical house and the only real difference is that it’s online. Your website’s homepage is where people come to visit you. It’s the family room of your website wh…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
Any person in technology especially those working for big companies should at least know about the basics of web accessibility. Believe it or not there are even laws in place that require businesses to provide such means for the disabled and aging p…

831 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