0

コンボボックスのテンプレート全体を取得して、いくつかの変更を加えました。ComboBoxItem のスタイルは次のとおりです。

    <Style x:Key="ComboBoxItemStyle" TargetType="{x:Type ComboBoxItem}">
        <Setter Property="OverridesDefaultStyle" Value="True"></Setter>
        <Setter Property="Background" Value="{DynamicResource StandardBlackBrush}"></Setter>
        <Setter Property="FocusVisualStyle" Value="{x:Null}"></Setter>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type ComboBoxItem}">
                    <Border x:Name="Bd" BorderBrush="{DynamicResource StandardBlackBrush}" BorderThickness="3" SnapsToDevicePixels="true" >
                        <ContentPresenter x:Name="Cp" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
                    </Border>       
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsHighlighted" Value="true">
                            <Setter TargetName="Bd" Property="BorderBrush" Value="{DynamicResource StandardFocusRectangleBrush}"/>
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style >             

これにより、テキスト文字列であるコンテンツの高さ/幅だけの非常に小さなコンボ ボックス項目が生成されます。これらのアイテムを大きくするために、ContentPresenter にマージンを追加すると、問題なく表示されます

<ContentPresenter Margin="20,10,20,10" x:Name="Cp" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>

ただし、マウス クリックはテキスト領域内で行う必要があります。テキストの外側で境界線内をマウスでクリックすると、ポップアップが閉じますが、選択は行われません。これは私の問題です。

4

1 に答える 1

1

これは、背景が設定されていない場合、境界線がマウス クリックに反応しないために発生します。

したがって、問題を解決するには、XAML の境界要素に次のように設定します。

Background="Transparent"
于 2012-11-28T20:02:16.253 に答える