【发布时间】:2015-11-17 01:49:27
【问题描述】:
我正在尝试在枢轴的一个部分设计瓷砖,其中包含纵向和横向的 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);
}
}
}
【问题讨论】:
标签: c# xaml grid universal setvalue