【问题标题】:How to obtain full width in PivotItem如何在 PivotItem 中获得全宽
【发布时间】:2013-09-05 09:33:02
【问题描述】:

在 XAML 中,PivotItems 在 Windows Phone 上没有整个屏幕宽度。这是很好的行为和设计,但对于单个图像,我希望它填满整个屏幕宽度。

这可以实现吗?

【问题讨论】:

  • 你试过玩边距吗?
  • 是的,我已将所有内容设置为 margin="0",从 Pivot 到 Grid,所有内容。
  • 贴一段xaml代码,对你有帮助会更容易。

标签: xaml windows-phone pivotviewer


【解决方案1】:

根本原因是默认的PivotItemMargin 设置为12,0,12,0。我们可以在 generic.xaml 中找到设置。

所以我们需要做的是覆盖 App.xaml 中的设置。就像这样:
<Thickness x:Key="PivotItemMargin">0</Thickness>

【讨论】:

  • 这才是真正的答案。负边距是错误的方法。
  • 这个答案是很久以后才添加的,但我完全同意!标记为答案!
【解决方案2】:

这是解决方案,边距为负

<controls:Pivot>
    <controls:PivotItem Margin="-10,0,-10,0">
        <Grid />
    </controls:PivotItem>

    <controls:PivotItem Margin="-10,0,-10,0">
        <Grid />
    </controls:PivotItem>
</controls:Pivot>

当然,您也可以使用常规枢轴,并且只将图像边距设置为 -10,0,-10,0

【讨论】:

  • 覆盖模板见下文。负边距是一种不好的做法。
【解决方案3】:

请使用此代码,

<phone:PhoneApplicationPage 
x:Class="NikhilSApp.DemoExample"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
xmlns:controls="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"     
mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="800"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
SupportedOrientations="Portrait"  Orientation="Portrait"
shell:SystemTray.IsVisible="False">

<!--LayoutRoot is the root grid where all page content is placed-->
<Grid x:Name="LayoutRoot" Background="Transparent">
    <!--Pivot Control-->

    // You can specify the width here....
    <controls:Pivot Height="800" Width="480">
        <!--Pivot item one-->
        <controls:PivotItem Height="800" Margin="0,-130,0,0">
            <Grid Name="GridMediaQuestion">
                <Image HorizontalAlignment="Center" Source="Images/Guess.png" Margin="10,10,10,10" Name="imgReceived" Stretch="Fill" VerticalAlignment="Center" Height="790" Width="470" />
            </Grid>
        </controls:PivotItem>

        <!--Pivot item two-->
        <controls:PivotItem Height="800" >
            <Grid x:Name="GridPivot2" Background="#ffffc0">
                 // Place Your Second pivot's  Content here
             </Grid>
        </controls:PivotItem>
    </controls:Pivot>
</Grid>

它正在工作.. 我已经实现了... :)

【讨论】:

  • 您也可以只为特定的一个 Pivot Item 指定宽度。
  • 但是根据这个页面,有多种分辨率可用。将其设置为 480 宽度并不能在每个设备上提供全宽? msdn.microsoft.com/en-us/library/windowsphone/develop/…
  • 然后您可以从后端设置它,例如 Pivot1.VerticalAlignment = System.Windows.VerticalAlignment.Stretch; Pivot1.Horizo​​ntalAlignment = System.Windows.Horizo​​ntalAlignment .Stretch;
  • 设置宽度没有帮助,因为有来自某处的边距。我尝试将宽度设置为 1000,但左侧仍有边距。也许 WPF 或 RT 的工作方式不同,但在 Windows Phone 中它不起作用。
猜你喜欢
  • 2018-12-04
  • 2013-10-12
  • 1970-01-01
  • 2013-08-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-02-28
  • 2014-10-20
相关资源
最近更新 更多