Reputation: 560
During i reading up on WPF i have run into a problem trying to create a binding on the Trigger in a template, used to create an image button.
<ControlTemplate x:Key="ToolbarButtonHover" TargetType="Button">
<Grid Name="backgroundGrid">
<Image Source="{DynamicResource ResourceKey=Img}" Width="{TemplateBinding Width}" Height="{TemplateBinding Height}"></Image>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="Button.IsPressed" Value="True">
<Setter TargetName="backgroundGrid" Property="Background" Value="#007ACC" />
</Trigger>
<!--Error: The property 'Binding' was not found in type Trigger-->
<Trigger Binding="{Binding Path=IsMouseOver, RelativeSource={RelativeSource TemplatedParent}}" Value="True">
<Setter TargetName="backgroundGrid" Property="Background" Value="Red" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
Results in the Error The property 'Binding' was not found in type Trigger
, more specifically its the line
<Trigger Binding="{ Path=IsMouseOver, RelativeSource={RelativeSource TemplatedParent}}" Value="True">
That generates it.
What is the reason for this error?
Upvotes: 2
Views: 2182
Reputation:
Probably because there is no Binding property on the Trigger class as you can see here.
You probably are looking for a DataTrigger.
<ControlTemplate x:Key="ToolbarButtonHover" TargetType="Button">
<Grid Name="backgroundGrid">
<Image Source="{DynamicResource ResourceKey=Img}" Width="{TemplateBinding Width}" Height="{TemplateBinding Height}"></Image>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="Button.IsPressed" Value="True">
<Setter TargetName="backgroundGrid" Property="Background" Value="#007ACC" />
</Trigger>
<!--Look below, DataTrigger -->
<DataTrigger Binding="{Binding Path=IsMouseOver, RelativeSource={RelativeSource TemplatedParent}}" Value="True">
<Setter TargetName="backgroundGrid" Property="Background" Value="Red" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
Upvotes: 10