[英]change selection animation in wpf listbox
I have to change animation in WPF listbox, because I use my own. 我必须在WPF列表框中更改动画,因为我使用了自己的动画。
The light blue is my selection (I made it with event select_changed and then I changed TextBlock.Background into lightblue) 浅蓝色是我的选择(我通过事件select_changed使其完成,然后将TextBlock.Background更改为浅蓝色)
The blue selection is the default, which I want to be transparent so that the selection will be more elegant. 蓝色选择是默认设置,我希望它是透明的,以便选择更优雅。
Does anyone know how to do that? 有谁知道这是怎么做到的吗?
Here is what I am currently doing: 这是我目前正在做的事情:
foreach (var item in myListBox.Items)
(item as TextBlock).Background = Brushes.White;
if (myListBox.SelectedItem != null)
(myListBox.SelectedItem as TextBlock).Background= Brushes.LightBlue;
myListBox.ScrollIntoView(myListBox.SelectedItem);
Just add this Style
to your ListBox
: 只需将此
Style
添加到您的ListBox
:
<Style x:Key="HiddenDefaultSelectionStyle" TargetType="{x:Type ListBoxItem}">
<Style.Resources>
<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" />
<SolidColorBrush x:Key="{x:Static SystemColors.ControlTextBrushKey}" Color="Black" />
</Style.Resources>
</Style>
You can replace the colour
Transparent
with whichever colour you prefer. 您可以用任意一种
colour
替换Transparent
色。 I believe that the names of these properties are self explanatory. 我相信这些属性的名称是不言自明的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.