tes*_*ing 12 xaml mobile-devices xamarin xamarin.forms mobile-development
对于UWP,我需要一个不同大小的列的宽度Grid.此外,平板电脑和智能手机的价值应该不同.
以下代码崩溃了应用程序
<ColumnDefinition>
<ColumnDefinition.Width>
<OnIdiom.Phone>
<OnPlatform x:TypeArguments="GridLength" iOS="*" Android="*" WinPhone="100" />
</OnIdiom.Phone>
<OnIdiom.Tablet>
<OnPlatform x:TypeArguments="GridLength" iOS="*" Android="*" WinPhone="200" />
</OnIdiom.Tablet>
</ColumnDefinition.Width>
</ColumnDefinition>
Run Code Online (Sandbox Code Playgroud)
同
在xmlns http://xamarin.com/schemas/2014/forms中找不到OnIdiom.Phone
代码在ViewCell.所以我不能使用额外的ResourceDictionary,也OnSizeAllocated()不能在代码隐藏文件中使用.
是否有可能使用OnIdiom和OnPlatform在一起?
Ste*_*oix 19
OnIdiom,就像OnPlatform你必须声明的对象一样.在您的情况下,您将OnIdiom.Phone属性设置为没有这些属性的对象.
你的Xaml看起来应该更像:
<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>
Run Code Online (Sandbox Code Playgroud)
自Xamarin.Forms v3.2起(通过新的内置XAML扩展),语法要好得多:
<Grid.ColumnDefinitions>
<ColumnDefinition Width="{OnIdiom
Phone= {OnPlatform iOS=*, Android=*, UWP=100 },
Tablet= {OnPlatform iOS=*, Android=*, UWP=200 }}">
</ColumnDefinition>
</Grid.ColumnDefinitions>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5455 次 |
| 最近记录: |