我有一个列表框,其listboxitem包含一个按钮,如下所示:
<DataTemplate x:Key="cDataTemplate" DataType="x:Type utils:cd">
<StackPanel Orientation="Horizontal" Background="Transparent">
<Button Style="{StaticResource LIButton}" x:Name="CButton"
Command="{x:Static this:EditorCommands.RaiseCMenu}"
CommandParameter="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListBoxItem}}}">
<Image Name="Image" Source="icon_c.jpg" Width="33" Height="21"/>
<Button.ContextMenu>
<ContextMenu x:Name="ctxtCard">
<MenuItem Header="..." Command="{x:Static this:EditorCommands.abc}"/>
<MenuItem Header="..." Command="{x:Static this:EditorCommands.def}"/>
</ContextMenu>
</Button.ContextMenu>
</Button>
<StackPanel Background="Transparent">
<TextBlock HorizontalAlignment="Left">
...
</TextBlock>
<TextBlock HorizontalAlignment="Left">
...
</TextBlock>
</StackPanel>
</StackPanel>
</DataTemplate>
<Style x:Key="cListBoxItemStyle" TargetType="ListBoxItem">
<Setter Property="ContentTemplate" Value="{DynamicResource cDataTemplate}"/>
<Setter Property="Background" Value="transparent"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListBoxItem">
<Border
Name="Border"
...
Background="Transparent">
<ContentPresenter Name="Content" HorizontalAlignment="Left" VerticalAlignment="Center" Opacity="0.55"/>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsSelected" Value="true">
<Setter TargetName="Border" Property="BorderBrush" Value="Black"/>
</Trigger>
<Trigger Property="IsSelected" Value="true">
<Setter TargetName="Border" Property="BorderThickness" Value="1,1,1,1"/>
</Trigger>
<Trigger Property="IsSelected" Value="true">
<Setter TargetName="Content" Property="Opacity" Value="1.0"/>
</Trigger>
<Trigger Property="IsMouseOver" Value="true">
<Setter TargetName="Content" Property="Opacity" Value="1.0"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
当单击未选中的listboxitem中的按钮时,它会触发其命令,这会在代码隐藏中引发上下文菜单并选择按钮的父listboxitem。 (重点是在左键单击时提高上下文菜单。)但是对于我的生活,当它的父列表框已被选中时,我无法触发该命令的按钮。奇怪的是,如果右键单击所选列表框中的按钮,它会适当地提升其上下文菜单,因此该按钮正在接收点击。
提前致谢!
答案 0 :(得分:0)
显然,当列表框中的选择模式设置为扩展时会发生这种情况。如果我找到解决办法的话,我会更新这个问题。