Answer the question
In order to leave comments, you need to log in
ListBox, how to recolor when item is selected?
Hello,
I just can’t understand how the inner element of the ListBox has a different color
<ListBox x:Name="vks"
HorizontalAlignment="Center"
VerticalAlignment="Center"
SelectionChanged="vks_SelectionChanged"
SelectionMode="Multiple"
ItemsSource="{Binding}" IsDoubleTapEnabled="False" IsHoldingEnabled="False" IsRightTapEnabled="False" IsTapEnabled="False" ManipulationMode="All" Foreground="Black" Background="Black">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel HorizontalAlignment="Center" VerticalAlignment="Center" Background="Black" >
<TextBlock Text="{Binding ShortText}" VerticalAlignment="Center" HorizontalAlignment="Center" Foreground="{ThemeResource AppBarItemForegroundThemeBrush}" />
<ListBox ItemsSource="{Binding mImages}"
HorizontalAlignment="Center"
VerticalAlignment="Center"
SelectionChanged="vks_SelectionChanged"
SelectionMode="Multiple"
RequestedTheme="Dark" Foreground="Black" Background="Black" BorderBrush="Black"
>
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel HorizontalAlignment="Center" VerticalAlignment="Center" Background="Black">
<TextBlock Text="{Binding linkMaxImage}" VerticalAlignment="Center" HorizontalAlignment="Center" />
<TextBlock Text="{Binding linkMaxImage}" VerticalAlignment="Center" HorizontalAlignment="Center" />
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
Answer the question
In order to leave comments, you need to log in
One of the options.
<!-- Создаем стиль, в котором переопределяем системный цвет выделения ListboxItem-->
<Style x:Key="vksStyle" TargetType="{x:Type ListBoxItem}">
<Style.Resources>
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}"
Color="Green"/>
</Style.Resources>
</Style>
<!--Назначаем созданный выше стиль ItemContainerStyle нашего ListBox-->
<ListBox ItemsSource="{Binding}"
ItemContainerStyle="{StaticResource vksStyle}">
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question