ComboBox->在右边添加这个小三角形

时间:2015-06-12 14:25:56

标签: c# combobox winrt-xaml

在WindowsPhone应用程序中的xaml中使用标准ComboBox时,ComboBox看起来不像旧样式ComboBox,即它右边没有这个小三角形。

有人能指出我的例子,或给我一个提示或解决方案:

我们如何将这个小三角形添加到ComboBox控件中。

我需要的只是让ComboBox看起来像:

enter image description here

谢谢!

这是我正在使用的代码:

<Page
    x:Class="ComboBoxCustom.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:ComboBoxCustom"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">

    <Page.Resources>
        <Style TargetType="ComboBox">
            <Setter Property="Padding" Value="8,0" />
            <Setter Property="MinWidth" Value="{ThemeResource ComboBoxThemeMinWidth}" />
            <Setter Property="Foreground" Value="{ThemeResource ComboBoxForegroundThemeBrush}" />
            <Setter Property="Background" Value="{ThemeResource ComboBoxBackgroundThemeBrush}" />
            <Setter Property="BorderBrush" Value="{ThemeResource ComboBoxBorderThemeBrush}" />
            <Setter Property="BorderThickness" Value="{ThemeResource ComboBoxBorderThemeThickness}" />
            <Setter Property="TabNavigation" Value="Once" />
            <Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Disabled" />
            <Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto" />
            <Setter Property="ScrollViewer.HorizontalScrollMode" Value="Disabled" />
            <Setter Property="ScrollViewer.VerticalScrollMode" Value="Auto" />
            <Setter Property="ScrollViewer.IsVerticalRailEnabled" Value="True" />
            <Setter Property="ScrollViewer.IsDeferredScrollingEnabled" Value="False" />
            <Setter Property="ScrollViewer.BringIntoViewOnFocusChange" Value="True" />
            <Setter Property="HorizontalContentAlignment" Value="Stretch" />
            <Setter Property="FontFamily" Value="{ThemeResource ContentControlThemeFontFamily}" />
            <Setter Property="FontSize" Value="{ThemeResource ControlContentThemeFontSize}" />

            <Setter Property="ItemsPanel">
                <Setter.Value>
                    <ItemsPanelTemplate>
                        <CarouselPanel />
                    </ItemsPanelTemplate>
                </Setter.Value>
            </Setter>

            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="ComboBox">
                        <Grid>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto" />
                                <RowDefinition Height="*" />
                            </Grid.RowDefinitions>

                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="*" />
                                <ColumnDefinition Width="32" />
                            </Grid.ColumnDefinitions>

                            <VisualStateManager.VisualStateGroups>
                                <VisualStateGroup x:Name="CommonStates">
                                    <VisualState x:Name="Normal" />
                                    <VisualState x:Name="PointerOver">
                                        <Storyboard>
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="Background"
                                                                   Storyboard.TargetProperty="Background">
                                                <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource ComboBoxPointerOverBackgroundThemeBrush}" />
                                            </ObjectAnimationUsingKeyFrames>
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="Background"
                                                                   Storyboard.TargetProperty="BorderBrush">
                                                <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource ComboBoxPointerOverBorderThemeBrush}" />
                                            </ObjectAnimationUsingKeyFrames>
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="Highlight"
                                                                   Storyboard.TargetProperty="Fill">
                                                <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource ComboBoxSelectedPointerOverBackgroundThemeBrush}" />
                                            </ObjectAnimationUsingKeyFrames>
                                        </Storyboard>
                                    </VisualState>
                                    <VisualState x:Name="Pressed">
                                        <Storyboard>
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="Background"
                                                                   Storyboard.TargetProperty="Background">
                                                <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource ComboBoxPressedBackgroundThemeBrush}" />
                                            </ObjectAnimationUsingKeyFrames>
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="Background"
                                                                   Storyboard.TargetProperty="BorderBrush">
                                                <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource ComboBoxPressedBorderThemeBrush}" />
                                            </ObjectAnimationUsingKeyFrames>
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenter"
                                                                   Storyboard.TargetProperty="Foreground">
                                                <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource ComboBoxPressedForegroundThemeBrush}" />
                                            </ObjectAnimationUsingKeyFrames>
                                            <DoubleAnimation Storyboard.TargetName="PressedBackground"
                                                     Storyboard.TargetProperty="Opacity"
                                                     To="1"
                                                     Duration="0" />
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="DropDownGlyph"
                                                                   Storyboard.TargetProperty="Foreground">
                                                <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource ComboBoxArrowPressedForegroundThemeBrush}" />
                                            </ObjectAnimationUsingKeyFrames>
                                        </Storyboard>
                                    </VisualState>
                                    <VisualState x:Name="Disabled">
                                        <Storyboard>
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="Background"
                                                                   Storyboard.TargetProperty="Background">
                                                <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource ComboBoxDisabledBackgroundThemeBrush}" />
                                            </ObjectAnimationUsingKeyFrames>
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="Background"
                                                                   Storyboard.TargetProperty="BorderBrush">
                                                <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource ComboBoxDisabledBorderThemeBrush}" />
                                            </ObjectAnimationUsingKeyFrames>
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenter"
                                                                   Storyboard.TargetProperty="Foreground">
                                                <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource ComboBoxDisabledForegroundThemeBrush}" />
                                            </ObjectAnimationUsingKeyFrames>
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="DropDownGlyph"
                                                                   Storyboard.TargetProperty="Foreground">
                                                <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource ComboBoxArrowDisabledForegroundThemeBrush}" />
                                            </ObjectAnimationUsingKeyFrames>
                                        </Storyboard>
                                    </VisualState>
                                </VisualStateGroup>
                                <VisualStateGroup x:Name="FocusStates">
                                    <VisualState x:Name="Focused">
                                        <Storyboard>
                                            <DoubleAnimation Storyboard.TargetName="HighlightBackground"
                                                     Storyboard.TargetProperty="Opacity"
                                                     To="1"
                                                     Duration="0" />
                                            <DoubleAnimation Storyboard.TargetName="Highlight"
                                                     Storyboard.TargetProperty="Opacity"
                                                     To="1"
                                                     Duration="0" />
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenter"
                                                                   Storyboard.TargetProperty="Foreground">
                                                <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource ComboBoxFocusedForegroundThemeBrush}" />
                                            </ObjectAnimationUsingKeyFrames>
                                        </Storyboard>
                                    </VisualState>
                                    <VisualState x:Name="FocusedPressed">
                                        <Storyboard>
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenter"
                                                                   Storyboard.TargetProperty="Foreground">
                                                <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource ComboBoxPressedForegroundThemeBrush}" />
                                            </ObjectAnimationUsingKeyFrames>
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="Highlight"
                                                                   Storyboard.TargetProperty="Fill">
                                                <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource ComboBoxPressedHighlightThemeBrush}" />
                                            </ObjectAnimationUsingKeyFrames>
                                        </Storyboard>
                                    </VisualState>
                                    <VisualState x:Name="Unfocused" />
                                    <VisualState x:Name="PointerFocused" />
                                    <VisualState x:Name="FocusedDropDown">
                                        <Storyboard>
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="PopupBorder"
                                                                   Storyboard.TargetProperty="Visibility"
                                                                   Duration="0">
                                                <DiscreteObjectKeyFrame KeyTime="0">
                                                    <DiscreteObjectKeyFrame.Value>
                                                        <Visibility>Visible</Visibility>
                                                    </DiscreteObjectKeyFrame.Value>
                                                </DiscreteObjectKeyFrame>
                                            </ObjectAnimationUsingKeyFrames>
                                        </Storyboard>
                                    </VisualState>
                                </VisualStateGroup>
                                <VisualStateGroup x:Name="DropDownStates">
                                    <VisualState x:Name="Opened">
                                        <Storyboard>
                                            <SplitOpenThemeAnimation
                                      OpenedTargetName="PopupBorder"
                                      ContentTargetName="ScrollViewer"
                                      ClosedTargetName="ContentPresenter"
                                      ContentTranslationOffset="0"
                                      OffsetFromCenter="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=TemplateSettings.DropDownOffset}"
                                      OpenedLength="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=TemplateSettings.DropDownOpenedHeight}"
                                      ClosedLength="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=TemplateSettings.DropDownClosedHeight}" />
                                        </Storyboard>
                                    </VisualState>
                                    <VisualState x:Name="Closed">
                                        <Storyboard>
                                            <SplitCloseThemeAnimation
                                      OpenedTargetName="PopupBorder"
                                      ContentTargetName="ScrollViewer"
                                      ClosedTargetName="ContentPresenter"
                                      ContentTranslationOffset="40"
                                      OffsetFromCenter="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=TemplateSettings.DropDownOffset}"
                                      ContentTranslationDirection="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=TemplateSettings.SelectedItemDirection}"
                                      OpenedLength="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=TemplateSettings.DropDownOpenedHeight}"
                                      ClosedLength="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=TemplateSettings.DropDownClosedHeight}" />
                                        </Storyboard>
                                    </VisualState>
                                </VisualStateGroup>
                            </VisualStateManager.VisualStateGroups>

                            <ContentPresenter x:Name="HeaderContentPresenter"
                                      Foreground="{ThemeResource ComboBoxHeaderForegroundThemeBrush}"
                                      Margin="{ThemeResource ComboBoxHeaderThemeMargin}"
                                      FlowDirection="{TemplateBinding FlowDirection}"
                                      FontWeight="{ThemeResource ComboBoxHeaderThemeFontWeight}"
                                      Visibility="Collapsed"  
                                      Content="{TemplateBinding Header}"
                                      ContentTemplate="{TemplateBinding HeaderTemplate}" />

                            <Border x:Name="Background"
                                Grid.Row="1"
                                Grid.ColumnSpan="2"
                                Background="{TemplateBinding Background}"
                                BorderBrush="{TemplateBinding BorderBrush}"
                                BorderThickness="{TemplateBinding BorderThickness}" />

                            <Rectangle x:Name="PressedBackground"
                               Grid.Row="1"
                               Fill="{ThemeResource ComboBoxPressedHighlightThemeBrush}"
                               Margin="{TemplateBinding BorderThickness}"
                               Opacity="0" />

                            <Border x:Name="HighlightBackground"
                                Grid.Row="1"
                                Grid.ColumnSpan="2"
                                Background="{ThemeResource ComboBoxFocusedBackgroundThemeBrush}"
                                BorderBrush="{ThemeResource ComboBoxFocusedBorderThemeBrush}"
                                BorderThickness="{TemplateBinding BorderThickness}"
                                Opacity="0" />

                            <Rectangle x:Name="Highlight"
                               Grid.Row="1"
                               Fill="{ThemeResource ComboBoxSelectedBackgroundThemeBrush}"
                               Margin="{TemplateBinding BorderThickness}"
                               Opacity="0" />

                            <ContentPresenter x:Name="ContentPresenter"
                                      Grid.Row="1"
                                      Margin="{TemplateBinding Padding}"
                                      HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                      VerticalAlignment="{TemplateBinding VerticalContentAlignment}">

                                <TextBlock x:Name="PlaceholderTextBlock"
                                   Text="{TemplateBinding PlaceholderText}"
                                   Foreground="{ThemeResource ComboBoxPlaceholderTextForegroundThemeBrush}"
                                   FontWeight="{ThemeResource ComboBoxPlaceholderTextThemeFontWeight}"/>

                            </ContentPresenter>

                            <TextBlock x:Name="DropDownGlyph"
                               Text="&#57361;"
                               Grid.Row="1"
                               Grid.Column="1"
                               IsHitTestVisible="False"
                               Margin="0,0,6,4"
                               Foreground="{ThemeResource ComboBoxArrowForegroundThemeBrush}"
                               FontWeight="Bold"
                               FontSize="{ThemeResource ComboBoxArrowThemeFontSize}"
                               FontFamily="{ThemeResource SymbolThemeFontFamily}"
                               HorizontalAlignment="Right"
                               VerticalAlignment="Center"
                               AutomationProperties.AccessibilityView="Raw"/>

                            <Popup x:Name="Popup">
                                <Border x:Name="PopupBorder"
                                    Background="{ThemeResource ComboBoxPopupBackgroundThemeBrush}"
                                    BorderBrush="{ThemeResource ComboBoxPopupBorderThemeBrush}"
                                    BorderThickness="{ThemeResource ComboBoxPopupBorderThemeThickness}"
                                    HorizontalAlignment="Stretch">

                                    <ScrollViewer x:Name="ScrollViewer" Foreground="{ThemeResource ComboBoxPopupForegroundThemeBrush}"
                                            MinWidth="{ThemeResource ComboBoxPopupThemeMinWidth}"
                                            VerticalSnapPointsType="OptionalSingle"
                                            VerticalSnapPointsAlignment="Near"
                                            HorizontalScrollMode="{TemplateBinding ScrollViewer.HorizontalScrollMode}"
                                            HorizontalScrollBarVisibility="{TemplateBinding ScrollViewer.HorizontalScrollBarVisibility}"
                                            VerticalScrollMode="{TemplateBinding ScrollViewer.VerticalScrollMode}"
                                            VerticalScrollBarVisibility="{TemplateBinding ScrollViewer.VerticalScrollBarVisibility}"
                                            IsHorizontalRailEnabled="{TemplateBinding ScrollViewer.IsHorizontalRailEnabled}"
                                            IsVerticalRailEnabled="{TemplateBinding ScrollViewer.IsVerticalRailEnabled}"
                                            IsDeferredScrollingEnabled="{TemplateBinding ScrollViewer.IsDeferredScrollingEnabled}"
                                            BringIntoViewOnFocusChange="{TemplateBinding ScrollViewer.BringIntoViewOnFocusChange}"
                                            ZoomMode="Disabled"
                                            AutomationProperties.AccessibilityView="Raw">
                                        <ItemsPresenter/>
                                    </ScrollViewer>
                                </Border>
                            </Popup>

                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </Page.Resources>


    <Grid>
        <ComboBox Header="asdswd"
                  Height="100">
            <ComboBox.Items>
                <TextBox Text="AAA"/>
                <TextBox Text="BBB"/>
            </ComboBox.Items>

        </ComboBox>


    </Grid>
</Page>

1 个答案:

答案 0 :(得分:0)

这是Windows Phone ComboBox的默认样式:

https://msdn.microsoft.com/en-us/library/windows/apps/xaml/jj709912.aspx

x:name =&#34; DropDownGlyph&#34;是你在找什么。看起来您要显示的符号是&amp;#57361。如果它没有显示,那么它可能是您正在使用的其他地方的样式,它会覆盖默认值。