Reputation: 659
I need some help with a binding error I'm getting from a style on a custom button. Here is the xaml:
<Style TargetType="{x:Type Controls:DropDownButton}" BasedOn="{StaticResource ButtonBaseStyle}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Controls:DropDownButton}">
<Border
x:Name="border"
Padding="{TemplateBinding Padding}"
HorizontalAlignment="{TemplateBinding HorizontalAlignment}"
VerticalAlignment="{TemplateBinding VerticalAlignment}">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Grid Grid.Column="0" >
<Border Padding="5">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid Grid.Row="0">
<Image
Style="{StaticResource DefaultImageStyle}"
Source="{Binding SmallImage, Converter={StaticResource LocalizingConverter}}">
<Image.Effect>
<ShaderEffects:GrayscaleEffect
DesaturationFactor="1"
IsEnabled="{Binding IsEnabled, RelativeSource={RelativeSource TemplatedParent}}"/>
</Image.Effect>
</Image>
</Grid>
<Grid Grid.Row="1">
<TextBlock
Style="{StaticResource DefaultTextHeaderStyle}"
Text="{Binding Name, Converter={StaticResource LocalizingConverter}}"/>
</Grid>
</Grid>
</Border>
</Grid>
<Grid
Grid.Column="1"
VerticalAlignment="Stretch">
<Polygon
x:Name="arrow"
Points="0,0 8,0 4,5"
Fill="{TemplateBinding Foreground}"
VerticalAlignment="Center"
HorizontalAlignment="Center"/>
</Grid>
</Grid>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
Which when the application starts up gives me the following binding error:
System.Windows.Data Error: 2 : Cannot find governing FrameworkElement or FrameworkContentElement for target element. BindingExpression:Path=IsEnabled; DataItem=null; target element is 'GrayscaleEffect' (HashCode=4769001); target property is 'IsEnabled' (type 'Boolean')
The image effect appears to be working fine, but whats the deal with the binding error and how do I fix it?
Upvotes: 1
Views: 627
Reputation: 2210
I don't think that Effect actually has a DataContext because it doesn't inherit from FrameworkContentElement, so it can't find the templated parent through an inherited DataContext. I've seen the same sort of thing with the Camera object, which also doesn't get DataContext. Check it out at: http://msdn.microsoft.com/en-us/library/system.windows.media.effects.effect.aspx
Is the IsEnabled part working correctly for you?
Upvotes: 1