2010-09-10 72 views
3

我在我的應用程序中使用ComboBox控件。我明白,它沒有支持的Metro主題 - 但一個ComboBox完全符合我的需求,所以我們在這裏......所以我的困境是我需要從零開始創建一個地鐵主題,或者我需要花費2天時間重新創建組合框控件。我嘗試了第一個選項(創建一個地鐵主題),但我有一些問題:Windows Phone組合框樣式的問題

  1. 文本總是白 - 不能弄清楚如何設置它。
  2. 我無法改變的選擇框(不下拉列表)
  3. 我無法改變滴的顏色下拉列表

我和混合周圍玩了幾個小時的顏色和無法看到如何更改這些值。任何幫助非常感謝。這裏是我當前的風格:

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

回答

0

側跨您的實際問題,Alex Yakhnin has created a ListPicker control其可如爲你一個合適的替代作用。它也很符合地鐵風格。
它也是開源的,所以你可以深入代碼,看看他如何處理主題。

+0

太好了,正是我在找的東西。將看看並回來。 – will 2010-09-10 19:57:06

+0

我認爲MS團隊的主要想法是「我們如何運送堅實的核心?」像這樣的UI元素雖然真的非常好,但可以在盒子外面傳遞(比如Alex的博客等)。另一方面,核心功能必須通過所有QA和平臺的測試,然後它必須等待整個野獸準備出貨。我認爲通過博客,Codeplex等進行out-of-band實際上是可以推出的,因爲它比等待官方發佈版本更快地發佈和升級功能。 – ctacke 2010-09-10 21:03:30

+0

您好,該團隊現在正在與社區進行諮詢,討論將包含在Windows Phone開發人員工具包中的控件。 ListPicker已經被提出。 – 2010-09-11 00:21:21

0

新的silverlight工具包已經發布,它有你想要的listpicker。

它更好地使用這一個,因爲它已經過很好的測試,而不是創建你自己的,並打開了錯誤的大門。