?
Solved

WPF issue with Trigger

Posted on 2016-10-09
2
Medium Priority
?
179 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
[X]
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
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
Suggested Courses

777 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