簡體   English   中英

列表框所選項目應以某種顏色突出顯示

[英]listbox selected item should highlight with some color

我有一些圖像的ListBox 我想用某種顏色突出顯示所選項目。 我正在使用WwrapPanel通過ScrollViewer水平顯示圖像。 有什么辦法可以解決我的問題?

您應該將ItemContainerStyle與IsSelected屬性上的觸發器一起使用,並在Trigger中將Setter放在Background屬性上

這應該可以解決問題:

<Window x:Class="StackOverflowTests.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Window1" x:Name="window1" Height="300" Width="300">
    <Window.Resources>
        <!-- Specifies the Selection style of ListBoxItems. This changes the forced underlay colors from gray to transparent. -->
        <Style TargetType="ListBoxItem">
            <Style.Resources>
                <!-- This is the color used if the item is selected and the listbox has focus -->
                <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Red"/>
            </Style.Resources>
        </Style>
    </Window.Resources>
    <Grid>
        <StackPanel Orientation="Vertical">
            <ListBox>
                <ListBoxItem Content="Item 1" />
                <ListBoxItem Content="Item 2" />
                <ListBoxItem Content="Item 3" />
                <ListBoxItem Content="Item 4" />
                <ListBoxItem Content="Item 5" />
                <ListBoxItem Content="Item 6" />
                <ListBoxItem Content="Item 7" />
                <ListBoxItem Content="Item 8" />
                <ListBoxItem Content="Item 9" />
                <ListBoxItem Content="Item 10" />
            </ListBox>
        </StackPanel>       
    </Grid>
</Window>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM