【发布时间】:2018-01-03 07:41:47
【问题描述】:
我正在使用一个自定义的 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>
ListBox 的已用 ItemsSource 的某条记录的已用 ListBoxItem 由 StyleSelector 选择。
我需要的是访问当前关注的 ListBoxItem 的可能性。我已经尝试了以下
- 将 ListBox 的 IsSyncronizedWithCurrentItem 属性设置为 true
- 尝试抓取 ListBox 的 SelectionChanged 事件
- 监控ListBoxItem的IsSelected属性
- 在 ListBoxItem 的基本样式中定义 (Multi)Trigger
- 设置一个 EventSetter
有人可以帮帮我吗?
提前非常感谢
【问题讨论】:
-
你能告诉我们你是如何尝试使用
Trigger的吗?我会使用DataTrigger和IsSelected属性。 -
好吧,不是真的,对不起。原因是我试图绑定/链接到 ViewModel 中的 EventHandler,这根本不起作用。但是否有可能看到,您的解决方案会是什么样子?
-
如果没有代码示例,您希望我们如何提供帮助?当然,您可以跳过任何您想要保密的敏感信息,这是关于复制您的尝试,然后找到正确的方法。
标签: wpf styles selecteditem listboxitem currentitem