2013-09-05 15 views
5

W XAML elementy PivotItems nie mają pełnej szerokości ekranu w systemie Windows Phone. To jest dobre zachowanie i konstrukcja, ale dla pojedynczego obrazu chcę, aby wypełniał całą szerokość ekranu.Jak uzyskać pełną szerokość w PivotItem

Czy można tego dokonać?

+0

Czy próbowałeś, grając z marginesami? – anderZubi

+0

Tak, afaik Ustawiłem wszystko na margin = "0", z Pivot na Grid, wszystko. –

+1

Opublikuj fragment kodu Xaml, łatwiej ci będzie pomóc. – anderZubi

Odpowiedz

5

Jest to rozwiązanie, posiadające ujemny margines

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

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

Oczywiście możesz również użyć zwykłego przestawnego i ustawić tylko margines obrazu na -10,0, -10,0

+0

Zobacz poniżej, aby przesłonić szablon. Negatywne marże są złą praktyką. – dex3703

0

użyj tego kodu,

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

to działa .. już wdrożony ... :)

+0

Możesz również określić szerokość tylko dla jednej pozycji przestawnej. –

+0

Ale według tej strony dostępnych jest wiele rozdzielczości. Ustawienie na 480 szerokości nie daje pełnej szerokości na każdym urządzeniu? http://msdn.microsoft.com/en-us/library/windowsphone/develop/jj206974%28v=vs.105%29.aspx –

+0

Następnie możesz ustawić go z tyłu tak, jak Pivot1.VerticalAlignment = System. Windows.VerticalAlignment.Stretch; Pivot1.HorizontalAlignment = System.Windows.HorizontalAlignment .Stretch; –

8

Podstawową przyczyną jest ustawienie domyślnej wartości PivotItemMargin na 12,0,12,0. Możemy znaleźć ustawienie w pliku generic.xaml.

To, co musimy zrobić, to przesłonić ustawienie w App.xaml. Po prostu tak:
<Thickness x:Key="PivotItemMargin">0</Thickness>

+0

To jest prawdziwa odpowiedź. Negatywne marże są niewłaściwą drogą. – dex3703

Powiązane problemy