2012-01-28 39 views
1

我需要在用戶做出選擇後減少列表選擇器在手機屏幕上佔用的空間量。我可以減少選定的項目的寬度,但我還沒有找到一種方法來減少高度。是的,我可以減小控件的大小,但標題總是佔用35個單位,而選定項目所採用的面板高度爲70.減小列表選擇器的高度使其看起來更小,但這隻會使底部所選項目顯示的面板。文本仍居中。設置VerticalContentAlignment不起作用,所以隨着高度的降低,文字會逐漸變得模糊。有沒有辦法降低所選項目顯示的面板的高度 - 或將所選文本的對齊方式移動到面板的頂部,然後清空未顯示任何文本的底部部分?如何在Windows Phone中設置Silverlight ListPicker中選定項目的高度

回答

1

這一點是可以通過在Expression Blend中的模板輕鬆完成 -

  1. 在Expression Blend中打開項目。
  2. 使用ListPicker導航到您的頁面。
  3. 在對象和時間線框中,找到您的ListPicker。
  4. 右擊,選擇編輯模板 - >編輯一個副本 - >輸入一個名稱來使用選擇定義在 - >應用程序,然後點擊確定。
  5. 單擊對象和時間線框中的網格。在屬性框中,輸入一個新的高度。我用36.
  6. 展開邊框
  7. 單擊UserControl。
  8. 在屬性窗口,更改從19磅的字體大小設置爲小尺寸(12磅)
  9. 現在,您創建的模板,你需要將它應用到所有listpickers像這樣:
<toolkit:ListPicker Style="{StaticResource ListPickerStyle1}"/> 

這裏的來源。

<Style x:Key="ListPickerStyle1" TargetType="toolkit:ListPicker"> 
       <Setter Property="Background" Value="{StaticResource PhoneTextBoxBrush}"/> 
       <Setter Property="Foreground" Value="{StaticResource PhoneTextBoxForegroundBrush}"/> 
       <Setter Property="BorderBrush" Value="{StaticResource PhoneTextBoxBrush}"/> 
       <Setter Property="BorderThickness" Value="{StaticResource PhoneBorderThickness}"/> 
       <Setter Property="FontSize" Value="{StaticResource PhoneFontSizeMediumLarge}"/> 
       <Setter Property="HorizontalContentAlignment" Value="Left"/> 
       <Setter Property="Margin" Value="{StaticResource PhoneTouchTargetOverhang}"/> 
       <Setter Property="PickerPageUri" Value="/Microsoft.Phone.Controls.Toolkit;component/ListPicker/ListPickerPage.xaml"/> 
       <Setter Property="Template"> 
        <Setter.Value> 
         <ControlTemplate TargetType="toolkit:ListPicker"> 
          <StackPanel> 
           <VisualStateManager.VisualStateGroups> 
            <VisualStateGroup x:Name="PickerStates"> 
             <VisualState x:Name="Normal"/> 
             <VisualState x:Name="Highlighted"> 
              <Storyboard> 
               <ObjectAnimationUsingKeyFrames Duration="0" Storyboard.TargetProperty="Background" Storyboard.TargetName="Border"> 
                <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource PhoneTextBoxEditBackgroundColor}"/> 
               </ObjectAnimationUsingKeyFrames> 
               <ObjectAnimationUsingKeyFrames Duration="0" Storyboard.TargetProperty="BorderBrush" Storyboard.TargetName="Border"> 
                <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource PhoneTextBoxEditBorderBrush}"/> 
               </ObjectAnimationUsingKeyFrames> 
              </Storyboard> 
             </VisualState> 
             <VisualState x:Name="Disabled"> 
              <Storyboard> 
               <ObjectAnimationUsingKeyFrames Duration="0" Storyboard.TargetProperty="Background" Storyboard.TargetName="Border"> 
                <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource TransparentBrush}"/> 
               </ObjectAnimationUsingKeyFrames> 
               <ObjectAnimationUsingKeyFrames Duration="0" Storyboard.TargetProperty="BorderBrush" Storyboard.TargetName="Border"> 
                <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource PhoneDisabledBrush}"/> 
               </ObjectAnimationUsingKeyFrames> 
               <ObjectAnimationUsingKeyFrames Duration="0" Storyboard.TargetProperty="Foreground" Storyboard.TargetName="UserControl"> 
                <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource PhoneDisabledBrush}"/> 
               </ObjectAnimationUsingKeyFrames> 
              </Storyboard> 
             </VisualState> 
            </VisualStateGroup> 
           </VisualStateManager.VisualStateGroups> 
           <ContentControl ContentTemplate="{TemplateBinding HeaderTemplate}" Content="{TemplateBinding Header}" Foreground="{StaticResource PhoneSubtleBrush}" FontSize="{StaticResource PhoneFontSizeNormal}" HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="0 0 0 8"/> 
           <Grid Height="36"> 
            <Border x:Name="Border" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}"> 
             <UserControl x:Name="UserControl" Foreground="{TemplateBinding Foreground}" FontSize="16"> 
              <StackPanel> 
               <TextBlock x:Name="MultipleSelectionModeSummary" Margin="8 8 0 8"/> 
               <Canvas x:Name="ItemsPresenterHost" MinHeight="46"> 
                <ItemsPresenter x:Name="ItemsPresenter"> 
                 <ItemsPresenter.RenderTransform> 
                  <TranslateTransform x:Name="ItemsPresenterTranslateTransform"/> 
                 </ItemsPresenter.RenderTransform> 
                </ItemsPresenter> 
               </Canvas> 
              </StackPanel> 
             </UserControl> 
            </Border> 
           </Grid> 
          </StackPanel> 
         </ControlTemplate> 
        </Setter.Value> 
       </Setter> 
      </Style> 
+0

謝謝,這解決了我的問題。 – user640142 2012-02-08 15:48:20

相關問題