Is it possible to mix OnIdiom and OnPlatform in XAML (Xamarin.Forms)?
Much nicer syntax as of Xamarin.Forms v3.2 (via new built-in XAML extensions):
<Grid.ColumnDefinitions>
<ColumnDefinition Width="{OnIdiom
Phone= {OnPlatform iOS=*, Android=*, UWP=100 },
Tablet= {OnPlatform iOS=*, Android=*, UWP=200 }}">
</ColumnDefinition>
</Grid.ColumnDefinitions>
Xamarin.Forms
Xaml Example:
<OnPlatform x:TypeArguments="View">
<OnPlatform.Android>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition>
<ColumnDefinition.Width>
<OnIdiom x:TypeArguments="GridLength" Tablet="100" Phone="50" />
</ColumnDefinition.Width>
</ColumnDefinition>
<ColumnDefinition>
<ColumnDefinition.Width>
<OnIdiom x:TypeArguments="GridLength" Tablet="100" Phone="50" />
</ColumnDefinition.Width>
</ColumnDefinition>
</Grid.ColumnDefinitions>
</Grid>
</OnPlatform.Android>
<OnPlatform.iOS>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition>
<ColumnDefinition.Width>
<OnIdiom x:TypeArguments="GridLength" Tablet="100" Phone="50" />
</ColumnDefinition.Width>
</ColumnDefinition>
<ColumnDefinition>
<ColumnDefinition.Width>
<OnIdiom x:TypeArguments="GridLength" Tablet="100" Phone="50" />
</ColumnDefinition.Width>
</ColumnDefinition>
</Grid.ColumnDefinitions>
</Grid>
</OnPlatform.iOS>
</OnPlatform>
OnIdiom
, just like OnPlatform
is an object you have to declare. In your case, you're setting OnIdiom.Phone
property to an object that doesn't have those.
Your Xaml should look more like:
<ColumnDefinition>
<ColumnDefinition.Width>
<OnIdiom x:TypeArguments="GridLength">
<OnIdiom.Phone>
<OnPlatform x:TypeArguments="GridLength" iOS="*" Android="*" WinPhone="100" />
</OnIdiom.Phone>
<OnIdiom.Tablet>
<OnPlatform x:TypeArguments="GridLength" iOS="*" Android="*" WinPhone="200" />
</OnIdiom.Tablet>
</OnIdiom>
</ColumnDefinition.Width>
</ColumnDefinition>