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>

この場合、Labelと のTextBlock両方が のクリック可能領域に重なっていComboBoxItemます。ComboBoxItem子コントロールの 1 つをクリックしたときに、クリックを無視したり、 に渡したりするにはどうすればよいですか?

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 に答える