I'm trying to change my ContentTemplate
using this code:
<DataTemplate x:Key="SidebarItemStyle" DataType="{x:Type domain:SidebarDataTemplate}">
<Grid>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Rectangle Grid.Row="0" Grid.RowSpan="2" Fill="{StaticResource BluePrimaryBrush}" />
<Image Grid.Row="0" Style="{StaticResource SidebarMenuImageSyle}" Source="{Binding Image}" />
<TextBlock Grid.Row="1" Style="{StaticResource SidebarMenuTextStyle}" Text="{Binding Title}" />
</Grid>
</DataTemplate>
<DataTemplate x:Key="SidebarSelectedItemStyle" DataType="{x:Type domain:SidebarDataTemplate}">
<Grid>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Rectangle Grid.Row="0" Grid.RowSpan="2" Fill="{StaticResource BluePrimaryBrush}" />
<Rectangle Grid.Row="0" Grid.RowSpan="2" Fill="{StaticResource TransparentOverlay1Brush}" />
<Image Grid.Row="0" Style="{StaticResource SidebarMenuImageSyle}" Source="{Binding SelectedImage}" />
<TextBlock Grid.Row="1" Style="{StaticResource SidebarMenuTextStyle}" Text="{Binding Title}" />
</Grid>
</DataTemplate>
<Style TargetType="{x:Type ListBoxItem}" x:Key="SidebarContainerStyle">
<Setter Property="ContentTemplate" Value="{StaticResource SidebarItemStyle}" />
<Style.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter Property="ContentTemplate" Value="{StaticResource SidebarSelectedItemStyle}" />
</Trigger>
</Style.Triggers>
</Style>
But, when I click on the item, it keeps selecting random item or selecting the first item only. The point is I want to use different Image
and add an overlay to the selected item.