Solved

WPF issue with Trigger

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

When it comes to write a Context Sensitive Help (an online help that is obtained from a specific point in state of software to provide help with that state) ,  first we need to make the file that contains all topics, which are given exclusive IDs. …
FAQ pages provide a simple way for you to supply and for customers to find answers to the most common questions about your company. Here are six reasons why your company website should have a FAQ page
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

685 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