网格 wp8.1 通用的 SetValue 崩溃
crash on SetValue for grids wp8.1 universal
我正在尝试在枢轴的一部分中设计具有 6 个纵向和横向瓷砖的瓷砖。我想要 3x2(3 行)的纵向图块和 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);
}
}
}
RowDefinition DependendyObject 中的 Height 不是 double 是 GridLenght class,所以你必须使用:
more_3rdrow.SetValue(RowDefinition.HeightProperty, new GridLength(172));
这是因为您可以定义自动、1* 或固定大小。所以也要小心 ColumDefinition
我正在尝试在枢轴的一部分中设计具有 6 个纵向和横向瓷砖的瓷砖。我想要 3x2(3 行)的纵向图块和 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);
}
}
}
RowDefinition DependendyObject 中的 Height 不是 double 是 GridLenght class,所以你必须使用:
more_3rdrow.SetValue(RowDefinition.HeightProperty, new GridLength(172));
这是因为您可以定义自动、1* 或固定大小。所以也要小心 ColumDefinition