Windows phone 7 如何在Windows Phone的Silverlight ListPicker中设置所选项目的高度

Windows phone 7 如何在Windows Phone的Silverlight ListPicker中设置所选项目的高度,windows-phone-7,listpicker,Windows Phone 7,Listpicker,在用户做出选择后,我需要减少listpicker在手机屏幕上占用的空间量。我可以减少所选项目的宽度,但我还没有找到降低高度的方法。是的,我可以减小控件的大小,但标题始终占据35个单位,而所选项目占据的面板高度为70。降低listpicker的高度会使其看起来更小,但这只会使所选项目显示的面板底部变黑。文本仍然居中。设置VerticalContentAlignment没有帮助,因此随着高度的降低,文本逐渐模糊。有没有办法降低显示所选项目的面板的高度?或者将所选文本的对齐方式移到面板的顶部,然后将不

在用户做出选择后,我需要减少listpicker在手机屏幕上占用的空间量。我可以减少所选项目的宽度,但我还没有找到降低高度的方法。是的,我可以减小控件的大小,但标题始终占据35个单位,而所选项目占据的面板高度为70。降低listpicker的高度会使其看起来更小,但这只会使所选项目显示的面板底部变黑。文本仍然居中。设置VerticalContentAlignment没有帮助,因此随着高度的降低,文本逐渐模糊。有没有办法降低显示所选项目的面板的高度?或者将所选文本的对齐方式移到面板的顶部,然后将不显示任何文本的底部部分清空?

这可以通过在Expression Blend中创建模板轻松完成--

  • 在Expression Blend中打开项目
  • 使用ListPicker导航到您的页面
  • 在“对象和时间线”框中,找到ListPicker
  • 右键单击,选择编辑模板->编辑副本->输入要使用的名称->在->应用程序中定义,然后单击确定
  • 单击“对象和时间线”框中的网格。在“属性”框中,输入新高度。我用了36
  • 扩展边界
  • 单击UserControl
  • 在“属性”窗口中,将字体大小从19磅更改为小字体(12磅)
  • 现在您已经创建了模板,您需要将其应用于所有列表选择器,如下所示:
  • 
    
    这是消息来源

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

    这可以通过在Expression Blend中创建模板轻松完成--

  • 在Expression Blend中打开项目
  • 使用ListPicker导航到您的页面
  • 在“对象和时间线”框中,找到ListPicker
  • 右键单击,选择编辑模板->编辑副本->输入要使用的名称->在->应用程序中定义,然后单击确定
  • 单击“对象和时间线”框中的网格。在“属性”框中,输入新高度。我用了36
  • 扩展边界
  • 单击UserControl
  • 在“属性”窗口中,将字体大小从19磅更改为小字体(12磅)
  • 现在您已经创建了模板,您需要将其应用于所有列表选择器,如下所示:
  • 
    
    这是消息来源

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