0
我有一個列表框,其ListBoxItem中包含,除其他事項外,一個按鈕,如下:按鈕ListBoxItem的忽略點擊內部時,它的父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中的按鈕,它會適時地引發其上下文菜單,因此該按鈕正在接收點擊。
在此先感謝!