WPF ListBox Image Selected the saga continues

后端 未结 1 827
慢半拍i
慢半拍i 2020-12-05 05:59

Ok in my ListBox scrolling images w/ text, etc. the saga continues. When I click one of the items, to select it, that runs a process to open a web browser and go to a specif

相关标签:
1条回答
  • 2020-12-05 06:44

    One trick I've found when playing with selection colours in a ListBox is to work with the system brushes rather than fighting against them.

    When a ListBox is focused and an item is selected, that item's background is SystemColors.HighlightBrush. When the ListBox loses focus, however, the selected item's background becomes SystemColors.ControlBrush.

    Knowing this, you can override the system brushes for that ListBox so that the items within are painted with the colours you want.

    <ListBox>
        <ListBox.Resources>
            <!-- override the system brushes so that selected items are transparent
                 whether the ListBox has focus or not -->
            <SolidColorBrush
                x:Key="{x:Static SystemColors.HighlightBrushKey}" 
                Color="Transparent" />
            <SolidColorBrush
                x:Key="{x:Static SystemColors.ControlBrushKey}" 
                Color="Transparent" />
            <SolidColorBrush
                x:Key="{x:Static SystemColors.HighlightTextBrushKey}" 
                Color="Black" />
        </ListBox.Resources>
        <!-- ... your items here ... -->
    </ListBox>
    
    0 讨论(0)
提交回复
热议问题