KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
The following code binds a GradientStop to the Background.Color property of TemplatedParent . Everything works but I am getting a binding error in the output window: System.Windows.Data Error: 2 : Cannot find governing FrameworkElement or FrameworkContentElement for target element. BindingExpression:Path=Background.Color; DataItem=null; target element is 'GradientStop' (HashCode=6944299); target property is 'Color' (type 'Color') <Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" x:Class="WpfBindingTest.MainWindow" x:Name="Window" Title="MainWindow" Width="100" Height="100"> <Window.Resources> <ControlTemplate x:Key="GradientTemplate" TargetType="{x:Type ContentControl}"> <Border BorderThickness="1" BorderBrush="{TemplateBinding Background}"> <Border.Background> <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0"> <GradientStop Color="{Binding Path=Background.Color, RelativeSource={RelativeSource TemplatedParent}}" Offset="1"/> <GradientStop Color="White" Offset="0"/> </LinearGradientBrush> </Border.Background> <ContentPresenter/> </Border> </ControlTemplate> </Window.Resources> <Grid x:Name="LayoutRoot"> <ContentControl Background="Green" Template="{StaticResource GradientTemplate}" > <TextBlock VerticalAlignment="Center" HorizontalAlignment="Center" Text="X" /> </ContentControl> </Grid> </Window>
Tags (comma-separated)
Save Edits
Cancel