Solved

WPF issue with Trigger

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
Any business that wants to seriously grow needs to keep the needs and desires of an international audience of their websites in mind. Making a website friendly to international users isn’t prohibitively expensive and can provide an incredible return…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

707 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now