Windows Phone ComboBox 样式问题

3
我在我的应用程序中使用了ComboBox控件。我知道它没有支持的Metro主题,但是ComboBox完美地满足了我的需求,所以我们就用它了……我的困境是我需要从头开始创建一个Metro主题,或者花费大约两天的时间重新创建ComboBox控件。我尝试了第一种选项(创建Metro主题),但遇到了一些问题:
  1. 文本始终为白色-无法设置。
  2. 我无法更改选择框(而不是下拉列表)的颜色。
  3. 我无法更改下拉列表的颜色。
我已经在Blend上尝试了几个小时,也找不到如何更改这些值。非常感谢任何帮助。这是我的当前样式:
    <Style x:Key="ComboBoxItemStyle" TargetType="ComboBoxItem">
        <Setter Property="Background" Value="{x:Null}"/>
        <Setter Property="BorderThickness" Value="0"/>
        <Setter Property="BorderBrush" Value="Transparent"/>
        <Setter Property="Padding" Value="0"/>
        <Setter Property="HorizontalContentAlignment" Value="Left"/>
        <Setter Property="VerticalContentAlignment" Value="Top"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="ComboBoxItem">
                    <Border x:Name="LayoutRoot"
                            BorderThickness="{TemplateBinding BorderThickness}" 
                            HorizontalAlignment="{TemplateBinding HorizontalAlignment}" 
                            VerticalAlignment="{TemplateBinding VerticalAlignment}">
                        <VisualStateManager.VisualStateGroups>
                            <VisualStateGroup x:Name="CommonStates">
                                <VisualState x:Name="Normal"/>
                                <VisualState x:Name="MouseOver"/>
                                <VisualState x:Name="Disabled">
                                    <Storyboard>
                                        <DoubleAnimation Duration="0" To=".5" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="ContentContainer"/>
                                    </Storyboard>
                                </VisualState>
                            </VisualStateGroup>
                            <VisualStateGroup x:Name="SelectionStates">
                                <VisualState x:Name="Unselected"/>
                                <VisualState x:Name="Selected"/>
                                <VisualState x:Name="SelectedUnfocused"/>
                            </VisualStateGroup>
                            <VisualStateGroup x:Name="FocusStates">
                                <VisualState x:Name="Unfocused"/>
                                <VisualState x:Name="Focused"/>
                            </VisualStateGroup>
                            <VisualStateGroup x:Name="LayoutStates">
                                <VisualState x:Name="AfterLoaded"/>
                                <VisualState x:Name="BeforeLoaded"/>
                                <VisualState x:Name="BeforeUnloaded"/>
                            </VisualStateGroup>
                        </VisualStateManager.VisualStateGroups>
                        <ContentControl x:Name="ContentContainer" 
                                        Background="Yellow"
                                        ContentTemplate="{TemplateBinding ContentTemplate}" 
                                        Content="{TemplateBinding Content}" 
                                        HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" 
                                        VerticalAlignment="{TemplateBinding VerticalContentAlignment}" Foreground="{StaticResource PhoneAccentBrush}"/>
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
    <ItemsPanelTemplate x:Key="ComboxBoxItemsTemplate">
        <StackPanel Background="Green"/>
    </ItemsPanelTemplate>

    <Style x:Key="ComboBoxStyle" TargetType="ComboBox">
        <Setter Property="HorizontalAlignment" Value="Stretch" />
        <Setter Property="ItemContainerStyle" Value="{StaticResource ComboBoxItemStyle}" />
        <Setter Property="ItemsPanel" Value="{StaticResource ComboxBoxItemsTemplate}" />
        <Setter Property="Foreground" Value="{StaticResource PhoneForegroundBrush}"/>

        <!-- The hue of the combo box selection box (not the drop down) -->
        <Setter Property="Background" Value="{StaticResource PhoneBackgroundBrush}"/>

        <!-- Effects BorderBrush for selection box and drop down -->
        <Setter Property="BorderBrush" Value="Transparent"/>
        <!-- Effects BorderThickness for selection box and drop down -->
        <Setter Property="BorderThickness" Value="0"/>

        <Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto"/>
        <Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto"/>
        <Setter Property="Padding" Value="0"/>
        <Setter Property="Margin" Value="6"/>            
    </Style>
2个回答

0
新的Silverlight工具包已经发布,它包含了你所需要的列表选择器。
最好使用这个工具包,因为它经过了充分测试,而不是自己开发,从而避免引入bug的可能性。

0

太好了,正是我想要的。我会看一下并回复。 - will
我认为微软团队的主要思考是“我们如何发布一个坚实的核心?”像这样的UI元素,虽然非常好用,但可以直接提供(例如Alex的博客等)。另一方面,核心功能必须经过平台的所有QA和测试,然后它必须等待整个系统准备好进行发布。我认为通过博客、Codeplex等方式进行带外发布实际上更可取,因为它比等待官方发布能够更快地发布和升级功能。 - ctacke
嗨Will,团队现在正在与社区商讨应该包括哪些控件在Windows Phone开发者工具包中。其中ListPicker已经被提出了。 - Mick N
谢谢Mick。只是好奇,你们如何与社区进行咨询?有没有一个页面可以让我添加我的愿望清单?谢谢。 - will

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接