我正在使用一个定制的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>它是我需要的编辑控件修改的基本结构,如下所示
<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>使用的ListBoxItem用于ListBox的已使用ItemsSource的特定记录,由StyleSelector选择。
我需要的是访问ListBoxItem的可能性,这是目前关注的焦点。我试过以下几种方法
有人能帮我吗?
提前谢谢
发布于 2018-01-03 11:05:44
好吧,以下是我的尝试:
<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>在ListBox的样式中,IsSyncronizedWithCurrentItem属性设置为true。
https://stackoverflow.com/questions/48073134
复制相似问题