1

Windows8 で WPF ComboBox コントロールをカスタマイズしようとしています。しかし、win8 では、これらのカスタマイズは ComboBox に影響を与えないように見えます。コンボボックスにはデフォルトのルック アンド フィールがあります。

例えば

< ComboBox Height="20" HorizontalAlignment="Left" Background="Red" BorderThickness="1" Name="comboBox1" VerticalAlignment="Top" Width="200" />

ここでは、コンボボックスに赤の背景を割り当てていますが、win8 では何の効果もありません。

ここで何か不足していますか?

4

2 に答える 2

1

コンボボックスを完全に制御するには、「追加のテンプレートを編集」することをお勧めします。これは、XAML のコンボボックス (DesignView) を右クリックして (C# と XAML を使用していると仮定)、[追加テンプレートの編集] に移動し、[生成されたアイテム コンテナーの編集] に移動してから [コピーの編集] に移動することで実行できます。これにより、「StandardStyles.xml」(デフォルト) にスタイルが作成され、自由に変更できます。私のために働いた。それがあなたにとってもうまくいくことを願っています。

スタイルで、視覚的な状態を探して、このように背景色を変更します

                            <VisualState x:Name="Selected">
                                <Storyboard>
                                    <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Background" Storyboard.TargetName="InnerGrid">
                                        <DiscreteObjectKeyFrame KeyTime="0" Value="#333333"/>
                                    </ObjectAnimationUsingKeyFrames>
                                    <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.TargetName="ContentPresenter">
                                        <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource ListBoxItemSelectedForegroundThemeBrush}"/>
                                    </ObjectAnimationUsingKeyFrames>
                                </Storyboard>
                            </VisualState>
                            <VisualState x:Name="SelectedUnfocused">
                                <Storyboard>
                                    <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Background" Storyboard.TargetName="InnerGrid">
                                        <DiscreteObjectKeyFrame KeyTime="0" Value="#333333"/>
                                    </ObjectAnimationUsingKeyFrames>
                                    <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.TargetName="ContentPresenter">
                                        <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource ListBoxItemSelectedForegroundThemeBrush}"/>
                                    </ObjectAnimationUsingKeyFrames>
                                </Storyboard>
                            </VisualState>
                            <VisualState x:Name="SelectedDisabled">
                                <Storyboard>
                                    <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Background" Storyboard.TargetName="InnerGrid">
                                        <DiscreteObjectKeyFrame KeyTime="0" Value="#333333"/>
                                    </ObjectAnimationUsingKeyFrames>
                                    <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.TargetName="ContentPresenter">
                                        <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource ListBoxItemSelectedDisabledForegroundThemeBrush}"/>
                                    </ObjectAnimationUsingKeyFrames>
                                </Storyboard>
                            </VisualState>
                            <VisualState x:Name="SelectedPointerOver">
                                <Storyboard>
                                    <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Background" Storyboard.TargetName="InnerGrid">
                                        <DiscreteObjectKeyFrame KeyTime="0" Value="#333333"/>
                                    </ObjectAnimationUsingKeyFrames>
                                    <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.TargetName="ContentPresenter">
                                        <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource ListBoxItemSelectedForegroundThemeBrush}"/>
                                    </ObjectAnimationUsingKeyFrames>
                                </Storyboard>
                            </VisualState>
                            <VisualState x:Name="SelectedPressed">
                                <Storyboard>
                                    <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Background" Storyboard.TargetName="InnerGrid">
                                        <DiscreteObjectKeyFrame KeyTime="0" Value="#333333"/>
                                    </ObjectAnimationUsingKeyFrames>
                                    <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.TargetName="ContentPresenter">
                                        <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource ListBoxItemSelectedForegroundThemeBrush}"/>
                                    </ObjectAnimationUsingKeyFrames>
                                </Storyboard>
                            </VisualState>

#333333ここで「赤」を指定できます。動作するはずです。

于 2012-10-08T04:50:42.073 に答える
0

Suny の提案に従いましたが、まだ赤の背景を取得できませんでした。そのため、ポップアップで背景を赤に変更したところ、赤を取得するのに役立ちました。

于 2013-01-08T16:25:23.150 に答える