0
我有一个列表框ItemContainerStyle
,它描述了列表框中每个元素的样式。像看起来是这样的:Listbox.ItemContainerStyle selected item
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem" BasedOn="{StaticResource MyStyle}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<Border BorderThickness="0,0,0,1" BorderBrush="#1f000000" Padding="16 8">
<Button Command={Binding MyCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=lists:MyControl}}}" />
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ListBox.ItemContainerStyle>
的事情是,当我点击这个按钮,我想知道在列表框中,这是在我的ViewModel绑定的SelectedItem
。除非我先选择该项目,否则此选择不会触发。
任何想法?
CommandParameter =“{结合的SelectedItem,的RelativeSource = {的RelativeSource模式= FindAncestor,AncestorType =列表:MyControl}“不起作用? –
只有在列表框中选择了任何项目时才会有效,但这里不是这种情况。 –
您的意思是说,当您选择的项目为空时,您无法检测到? –