简体   繁体   English

在启动时突出显示SelectedItem

[英]Highlight SelectedItem on start-up

I'm trying to highlight (with changing the background) SelectedItem in the collection on start-up. 我试图在启动时突出显示(更改背景)集合中的SelectedItem I have a data template to define the items. 我有一个数据模板来定义项目。 I can use a border to set the background. 我可以使用边框设置背景。 In the moment the highlight is done when an item is selected. 当选中一个项目时,突出显示完成。

<DataTemplate.Triggers>                       
    <DataTrigger Binding="{Binding Path=IsSelected, RelativeSource={RelativeSource FindAncestor, AncestorType=syncfusion:CarouselItem}}" Value="True">
       <Setter TargetName="border" Property="Background" Value="Red"/>
   </DataTrigger>
</DataTemplate.Triggers>

But because on start-up the SelectedItem is already active, it seems logic to be also highlighted. 但是因为在启动时SelectedItem已经处于活动状态,所以似乎也要突出显示逻辑。

Have you tried just selecting an item in the collection to ensure that one is selected? 您是否尝试过仅选择集合中的一项以确保已选中一项? You could declare a property of the type of the items that populate the collection to data bind to the ItemsControl.SelectedItem property. 您可以声明填充集合以将数据绑定到ItemsControl.SelectedItem属性的项目类型的属性。 Then in your code behind, or view model, you can do this (assuming your collection control is data bound to a data collection named Items : 然后,可以在后面的代码或视图模型中执行此操作(假设您的集合控件是绑定到名为Items的数据集合的数据:

<ListBox ItemsSource="{Binding Items}" SelectedItem="{Binding SelectedItem}" ... />

... ...

Items = FillCollectionWithItems();
if (Items.Count > 0) SelectedItem = Items[0];

My first thought would be the item is Selected, but not Focused, and the system color for selected but not focused is usually a really light gray that's hard to see. 我首先想到的是“已选择”项,而不是“已聚焦”项,而已选定但未聚焦的系统颜色通常是真正的浅灰色,很难看到。

You could try ensuring that the item has Focus on load if this is the case, or overwrite the system colors for the control. 在这种情况下,您可以尝试确保该项目具有“专注于负载”,或覆盖控件的系统颜色

Here's an example that overwrites the InactiveSelectionHighlightBrush color for a control: 这是一个覆盖控件的InactiveSelectionHighlightBrush颜色的示例:

<SomeControl.Resources>
    <SolidColorBrush x:Key="{x:Static SystemColors.InactiveSelectionHighlightBrush}" Color="Red"/>
</SomeControl.Resources>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM