[英]ListBox CurrentItem / SelectedItem
I'm using a custom ListBoxItem, that's built like this 我正在使用一个自定义的ListBoxItem,它是这样构建的
<Style x:Key="MyListBoxItem" TargetType="{x:Type ListBoxItem}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ListBoxItem}">
<Border>
<Border>
<ContentPresenter />
</Border>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
It's a basic structure which is modified for the editing control that I need, like this 这是一个基本结构,针对我需要的编辑控件进行了修改,例如
<Style x:Key="MyListBoxItemText" TargetType="{x:Type ListBoxItem}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ListBoxItem}">
<ListBoxItem Style="{DynamicResource MyListBoxItem}">
<TextBox />
</ListBoxItem>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
The used ListBoxItem for a certain record of the used ItemsSource of the ListBox is chosen by a StyleSelector. 由StyleSelector选择ListBox的ItemsItemSource的特定记录所使用的ListBoxItem。
What I need is a possibility to access the ListBoxItem, thats currently focused. 我需要的是访问ListBoxItem的可能性,这就是当前的重点。 I've tried the following
我尝试了以下
Can anyone help me, please? 有人可以帮我吗?
Thanks a lot in advance 提前谢谢
Alright, here are my attempts: 好吧,这是我的尝试:
<ControlTemplate.Triggers>
<DataTrigger Binding="{Binding Selector.IsSelected}" Value="True">
<Setter Property="Background" Value="Salmon" />
</DataTrigger>
</ControlTemplate.Triggers>
<ControlTemplate.Triggers>
<DataTrigger Binding="{Binding ListBoxItem.IsSelected}" Value="True">
<Setter Property="Background" Value="Salmon" />
</DataTrigger>
</ControlTemplate.Triggers>
<ControlTemplate.Triggers>
<DataTrigger Binding="{Binding IsSelected}" Value="True">
<Setter Property="Background" Value="Salmon" />
</DataTrigger>
</ControlTemplate.Triggers>
In the style of the ListBox the IsSyncronizedWithCurrentItem property is set to true. 按照ListBox的样式,IsSyncronizedWithCurrentItem属性设置为true。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.