2010-10-21 76 views
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中的按钮,它会适时地引发其上下文菜单,因此该按钮正在接收点击。

在此先感谢!

回答

0

显然,当列表框上的selectionmode设置为扩展时会发生这种情况。如果我找到解决方法,我会更新这个问题。