【问题标题】:Problem with Windows Phone ComboBox StyleWindows Phone 组合框样式的问题
【发布时间】:2010-09-10 17:31:46
【问题描述】:

我在我的应用程序中使用了 ComboBox 控件。我知道它没有受支持的 Metro 主题 - 但是 ComboBox 非常适合我的需求,所以我们在这里......所以我的困境是我需要从头开始创建一个 Metro 主题,或者我需要花费 2 天时间重新创建 ComboBox 控件。我尝试了第一个选项(创建地铁主题)但遇到了一些问题:

  1. 文本始终为白色 - 不知道如何设置。
  2. 我无法更改选择框的颜色(不是下拉列表)
  3. 我无法更改下拉列表的颜色

我已经玩过 Blend HOURS 了,但不知道如何更改这些值。非常感谢任何帮助。这是我目前的风格:

    <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>

【问题讨论】:

    标签: silverlight-4.0 windows-phone-7


    【解决方案1】:

    将您的实际问题放在一边,Alex Yakhnin has created a ListPicker control,这可能是您的合适选择。它也非常符合地铁风格。
    它也是开源的,所以你可以深入研究代码,看看他是如何处理主题的。

    【讨论】:

    • 太好了,正是我想要的。会看看然后回来。
    • 我认为 MS 团队的主要想法是“我们如何发布一个坚实的核心?”像这样的 UI 元素虽然非常非常好,但可以开箱即用(如 Alex 的博客等)。另一方面,核心功能必须经过平台的所有 QA 和测试,然后必须等待整个野兽准备好发布。我认为通过博客、Codeplex 等进行带外发布实际上是可取的,因为与等待正式发布相比,它允许更快地发布和升级功能。
    • 您好,Will,该团队正在与社区就 Windows Phone 开发人员工具包中包含的控件进行协商。 ListPicker 已被提升。
    • 谢谢米克。只是好奇,你们是如何与社区协商的?有没有我可以去添加我的愿望清单的页面?谢谢,
    【解决方案2】:

    新的 silverlight 工具包已经发布,它有你想要的列表选择器。

    最好使用这个,因为它已经过很好的测试,而不是创建自己的并为错误打开大门。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-01
      相关资源
      最近更新 更多