Emitting Click Events in WPF / XAML Composite Controls

So let's say I have 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 Label

, TextBlock

both overlap the area with a click for ComboBoxItem

. How do I ignore and / or pass the click to ComboBoxItem

when I click one of its child controls?

+2


source to share


1 answer


Just set the IsHitTestVisible property to 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>

      

+2


source







All Articles