2009-10-14 9 views
2

Alors, disons que j'ai un DataTemplate:Events Passing Cliquez sur Composite WPF/XAML Contrôles

<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> 

Dans ce cas, le Label et la TextBlock se chevauchent à la fois la zone cliquable pour la ComboBoxItem. Comment puis-je ignorer et/ou passer un clic sur le ComboBoxItem lorsque je clique sur l'un de ses contrôles enfants?

Répondre

2

situé à seulement la propriété IsHitTestVisible false pour ces éléments:

<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

Bizarre. J'ai essayé cela auparavant en ajoutant IsHitTestVisible = False sur le Label et TextBlock seulement. Il semble que vous deviez l'ajouter à ComboBoxItem, ce qui semble un peu paradoxal: je veux sélectionner un ComboBoxItem, pourquoi ne pas le tester? En tout cas, merci pour la solution! –