2009-10-14 47 views
2

所以,让我们说我有一个DataTemplate传递单击复合WPF/XAML活动控制

<DataTemplate x:Key="ProjectsDataItemTemplate"> 
    <ComboBoxItem x:Name="ProjectComboBox" 
        Opacity="1" HorizontalAlignment="Stretch" 
        Foreground="#FF80BBD2" 
        VerticalAlignment="Center" VerticalContentAlignment="Center" 
        Background="Transparent" 
        Style="{DynamicResource ComboBoxItemStyle1}"> 
     <StackPanel> 
      <Label Content="{Binding Name}" Height="32" VerticalContentAlignment="Top" 
        FontWeight="Bold" Foreground="#FFFEF9F9" AllowDrop="True" /> 
      <TextBlock Text="{Binding Description}" 
         Foreground="#FF80BBD2" 
         Padding="5,0,0,10" 
         FontStyle="Italic" /> 
     </StackPanel> 
    </ComboBoxItem> 
</DataTemplate> 

在这种情况下,LabelTextBlock两个重叠的ComboBoxItem可点击区域。当我点击其中一个子控件时,如何忽略和/或传递点击到ComboBoxItem

回答

2

只需设置IsHitTestVisible属性设置为false这些元素:

<DataTemplate x:Key="ProjectsDataItemTemplate"> 
    <ComboBoxItem x:Name="ProjectComboBox" 
        Opacity="1" 
        HorizontalAlignment="Stretch" 
        Foreground="#FF80BBD2" 
        VerticalAlignment="Center" 
        VerticalContentAlignment="Center" 
        Background="Transparent" 
        Style="{DynamicResource ComboBoxItemStyle1}"> 
      <StackPanel> 
       <Label IsHitTestVisible="False" 
         Content="{Binding Name}" 
         Height="32" 
         VerticalContentAlignment="Top" 
         FontWeight="Bold" 
         Foreground="#FFFEF9F9" 
         AllowDrop="True" /> 
       <TextBlock IsHitTestVisible="False" 
          Text="{Binding Description}" 
          Foreground="#FF80BBD2" 
          Padding="5,0,0,10" 
          FontStyle="Italic" /> 
      </StackPanel> 
    </ComboBoxItem> 
</DataTemplate> 
+0

奇怪。我之前通过在Label和TextBlock上添加IsHitTestVisible = False来尝试。它看起来像你必须将它添加到ComboBoxItem,这似乎有点违反直觉:我想选择一个ComboBoxItem为什么我不希望它测试?无论如何,谢谢你的解决方案! – 2009-10-14 20:58:26