2

所以,假设我有一个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>

在这种情况下,LabelTextBlock都与 的可点击区域重叠ComboBoxItemComboBoxItem当我单击其中一个子控件时,如何忽略和/或传递单击?

4

1 回答 1

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>
于 2009-10-14T20:24:10.227 回答