Y
Y
Younus2015-03-02 16:27:26
Windows
Younus, 2015-03-02 16:27:26

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>

I also noticed when setting IsEnabled="False" an external frame appears, which I also don't know how to repaint.
Please help, thanks in advance

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey, 2015-03-03
@Younus

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 question

Ask a Question

731 491 924 answers to any question