2012-10-03 26 views
1

我想在Windows8上自定義WPF組合框控件。但是看起來像win8這些定製對ComboBox沒有任何影響,ComboBox具有默認的外觀和感覺。在Windows8中的WPF組合框自定義

e.g

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

我在這裏assiging的組合框紅色背景,但Win8的這個沒有任何效果。

我在這裏錯過了什麼嗎?

回答

1

您可能想要「編輯附加模板」以對Combobox進行完全控制。 可以通過右鍵點擊XAML中的組合框(DesignView)(假設您正在使用C#和XAML)並轉到「編輯附加模板」,然後轉到「編輯Genereated Item Container」,然後轉到「編輯副本」 。 這將在「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是THA值,我給it.You可以在這裏指定「紅色」。 應該工作。

0

我按照Suny的建議,仍然無法獲得紅色背景,所以我在Popup中將背景更改爲紅色,這幫助我獲得了紅色。