2013-09-05 33 views
5

Trong XAML, PivotItems không có chiều rộng toàn màn hình trên Windows Phone. Đây là hành vi và thiết kế tốt, nhưng đối với một hình ảnh tôi muốn nó lấp đầy toàn bộ màn hình.Cách lấy chiều rộng đầy đủ trong PivotItem

Điều này có thể thực hiện được không?

+0

bạn đã thử bằng cách chơi với lề không? – anderZubi

+0

Có, afaik Tôi đã đặt mọi thứ thành margin = "0", từ Pivot thành Grid, mọi thứ. –

+1

Đăng một số đoạn mã xaml, nó sẽ giúp bạn dễ dàng hơn. – anderZubi

Trả lời

5

Đây là giải pháp, có một biên độ tiêu cực

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

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

Tất nhiên, bạn cũng có thể sử dụng trục xoay thông thường và chỉ có lề hình ảnh được đặt thành -10,0, -10,0

+0

Xem bên dưới để ghi đè mẫu. Lợi nhuận tiêu cực là một thực tế xấu. – dex3703

0

Hãy Sử dụng mã này,

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

Nó được làm việc .. tôi thực hiện đã ... :)

+0

Bạn cũng có thể chỉ định chiều rộng cho một Mục Pivot cụ thể. –

+0

Nhưng theo trang này, có nhiều độ phân giải có sẵn. Đặt nó ở độ rộng 480 không cho chiều rộng đầy đủ trên mọi thiết bị? http://msdn.microsoft.com/en-us/library/windowsphone/develop/jj206974%28v=vs.105%29.aspx –

+0

thì bạn có thể đặt từ đầu sau như Pivot1.VerticalAlignment = System. Windows.VerticalAlignment.Stretch; Pivot1.HorizontalAlignment = System.Windows.HorizontalAlignment .Stretch; –

8

Nguyên nhân gốc là mặc định PivotItemMargin được đặt thành 12,0,12,0. Chúng ta có thể tìm thấy thiết lập trong generic.xaml.

Vì vậy, những gì chúng tôi cần làm là ghi đè cài đặt trong App.xaml. Chỉ cần như thế này:
<Thickness x:Key="PivotItemMargin">0</Thickness>

+0

Đây là câu trả lời thực sự. Lợi nhuận tiêu cực là sai lầm để đi. – dex3703

Các vấn đề liên quan