0

I've managed to create a ListboxItemTemplate with a Path and a Textblock. I've set the styles for the Path so that when the mouse is over it will change colours. My XAML below is:

<DataTemplate x:Key="WorkingFileTemplate"> <Grid HorizontalAlignment="Left"> <StackPanel Orientation="Horizontal" Height="Auto" ToolTip="{Binding Path}" HorizontalAlignment="Left"> <Path x:Name="ButtonPath" Stroke="#FFEA3E3E" StrokeStartLineCap="Round" StrokeEndLineCap="Round" Stretch="Uniform" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Margin="0,5.75,0,4.625" StrokeThickness="2.55" Width="11.25" Height="Auto" Data="M0,0 L25,25 M0,25 L25,0"> <Path.Style> <Style TargetType="Path"> <Style.Triggers> <Trigger Property="IsMouseOver" Value="True"> <Setter Property="Stroke" Value="White" /> </Trigger> <Trigger Property="IsMouseOver" Value="False"> <Setter Property="Stroke" Value="#FFEA3E3E" /> </Trigger> </Style.Triggers> </Style> </Path.Style> </Path> <TextBlock Text="{Binding Name}" TextTrimming="CharacterEllipsis" Margin="5,2,0,0" TextOptions.TextFormattingMode="Display" VerticalAlignment="Top" HorizontalAlignment="Stretch" FontSize="13.333" Foreground="#FFC9C9C9"/> </StackPanel> </Grid> </DataTemplate> 

Why doesn't it work when I hover over the mouse? It stimple doesn't get activated.

1 Answer 1

2

You may need to use a ControlTemplate.Trigger. Here, I added a button and have a ControlTemplate.

<Button> <Button.Template> <ControlTemplate> <Path x:Name="ButtonPath" Stroke="#FFEA3E3E" StrokeStartLineCap="Round" StrokeEndLineCap="Round" Stretch="Uniform" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Margin="0,5.75,0,4.625" StrokeThickness="2.55" Width="11.25" Height="Auto" Data="M0,0 L25,25 M0,25 L25,0"> </Path> <ControlTemplate.Triggers> <Trigger Property="IsMouseOver" Value="True"> <Setter TargetName="ButtonPath" Property="Stroke" Value="Blue" /> </Trigger> <Trigger Property="IsMouseOver" Value="False"> <Setter TargetName="ButtonPath" Property="Stroke" Value="#FFEA3E3E" /> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Button.Template> </Button> 
Sign up to request clarification or add additional context in comments.

2 Comments

Did it not work because I needed something like a button?
@F4z Something like that. In other words, we need to use ControlTemplate.Triggers for this requirement and we can do that in Button. But it can be done to many more controls not just button.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.