我试图在枢轴的一个部分设计瓷砖,其中有6个瓷砖,包括纵向和横向。我希望3x2(3rows)瓷砖用于纵向,2x3瓷砖用于横向。它在没有c#代码的两种模式下显示3x2但在添加该代码后,它会在第一个Setvalue上崩溃。
我的xaml代码:
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="172"/>
<RowDefinition Height="172"/>
<RowDefinition x:Name="more_3rdrow" Height="172"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="172"/>
<ColumnDefinition Width="172"/>
<ColumnDefinition x:Name="more_3rdcolumn" Width="0"/>
</Grid.ColumnDefinitions>
<Grid Grid.Row="0" Grid.Column="0" x:Name="contacttile">
some data here
</Grid>
<Grid Grid.Row="0" Grid.Column="1" x:Name="ratetile">
some data here
</Grid>
<Grid Grid.Row="1" Grid.Column="0" x:Name="moreappstile">
some data here
</Grid>
more grids here
</Grid>
我的c#代码:
private void pivot_Loaded(object sender, RoutedEventArgs e)
{
moresectionLoaded = 1;
}
private void PageBase_SizeChanged(object sender, SizeChangedEventArgs e)
{
if (moresectionLoaded == 1)
{
string currentviewstate = ApplicationView.GetForCurrentView().Orientation.ToString();
if (currentviewstate == "Portrait")
{
///crashes in below line
more_3rdrow.SetValue(RowDefinition.HeightProperty, 172);
more_3rdcolumn.SetValue(ColumnDefinition.WidthProperty, 0);
moreappstile.SetValue(Grid.RowProperty, 1);
moreappstile.SetValue(Grid.ColumnProperty, 0);
abouttile.SetValue(Grid.RowProperty, 1);
abouttile.SetValue(Grid.ColumnProperty, 1);
pintile.SetValue(Grid.RowProperty, 2);
pintile.SetValue(Grid.ColumnProperty, 0);
pintypestile.SetValue(Grid.RowProperty, 2);
pintypestile.SetValue(Grid.ColumnProperty, 1);
}
if (currentviewstate == "Landscape")
{
///crashes in below line
more_3rdrow.SetValue(RowDefinition.HeightProperty, 0);
more_3rdcolumn.SetValue(ColumnDefinition.WidthProperty, 172);
moreappstile.SetValue(Grid.RowProperty, 0);
moreappstile.SetValue(Grid.ColumnProperty, 2);
abouttile.SetValue(Grid.RowProperty, 1);
abouttile.SetValue(Grid.ColumnProperty, 0);
pintile.SetValue(Grid.RowProperty, 1);
pintile.SetValue(Grid.ColumnProperty, 1);
pintypestile.SetValue(Grid.RowProperty, 1);
pintypestile.SetValue(Grid.ColumnProperty, 2);
}
}
}