tags:

views:

45

answers:

1

So, let's say I have a DataTemplate

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

In this case, the Label and the TextBlock both overlap the clickable area for the ComboBoxItem. How do I ignore and/or pass a click through to the ComboBoxItem when I click one of its child controls?

+1  A: 

Just set the IsHitTestVisible property to false for those elements:

<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>
Reed Copsey
Weird. I tried that before by adding IsHitTestVisible=False on the Label and TextBlock only. It looks like you have to add it to the ComboBoxItem as well which seems a bit counterintuitive: I want to select a ComboBoxItem why would I not want it hit tested? Anyway, thanks for the solution!
Tyler Schlegel