我需要使用OnIdiom进行网格列定义,但它不起作用。请参阅下面的代码。谁能告诉我我做错了什么并建议解决方案?
<Grid.ColumnDefinitions>
<ColumnDefinition>
<ColumnDefinition.Width>
<OnIdiom x:TypeArguments="GridLength" Tablet="64.9*" Phone="99.8*"/>
</ColumnDefinition.Width>
</ColumnDefinition>
<ColumnDefinition>
<ColumnDefinition.Width>
<OnIdiom x:TypeArguments="GridLength" Tablet="0.1*" Phone="0.1*"/>
</ColumnDefinition.Width>
</ColumnDefinition>
<ColumnDefinition>
<ColumnDefinition.Width>
<OnIdiom x:TypeArguments="GridLength" Tablet="35*" Phone="0.1*"/>
</ColumnDefinition.Width>
</ColumnDefinition>
这没有用,所以我做了:
<Grid.ColumnSpan>
<OnIdiom x:TypeArguments="x:Int32" Phone="3" Tablet="1"/>
</Grid.ColumnSpan>
这也没有帮助。
答案 0 :(得分:0)
override void OnSizeAllocated(double width, double height)
{
//according with height and width you can design your layouts
if (Device.Idiom == TargetIdiom.Phone)
{
// layout views vertically
}
else
{
// layout views horizontally or use different Page
}
}
答案 1 :(得分:0)
x:DataType代替x:TypeArguments对我有用。
<Grid.RowDefinitions>
<RowDefinition >
<RowDefinition.Height>
<OnIdiom x:DataType="GridLength" Tablet=".25*" Phone="0.075*" />
</RowDefinition.Height>
</RowDefinition>
<RowDefinition >
<RowDefinition.Height>
<OnIdiom x:DataType="GridLength" Tablet="*" Phone="0.85*" />
</RowDefinition.Height>
</RowDefinition>
<RowDefinition >
<RowDefinition.Height>
<OnIdiom x:DataType="GridLength" Tablet=".25*" Phone="0.075*" />
</RowDefinition.Height>
</RowDefinition>
</Grid.RowDefinitions>