安装
1、查看Xaramin.Forms的版本
在vs项目中查看引用的包(Xamarin.Forms)的版本,或者直接进文件夹看 C:\Microsoft\Xamarin\NuGet\xamarin.forms\
可以通过 NuGet 更新到最新的 Xamarin 版本。
开发
XAML
1、xaml中用到的StaticResource的定义
<Setter Property="FontFamily" Value="{StaticResource MontserratRegular}" />
一般在App.xaml中的<Application.Resources><ResourceDictionary>中定义
2、xaml中实例化对象
在xaml上面定义的命名空间别名, xmlns:behaviors="clr-namespace:SkillPool.Core.Behaviors"
使用的时候其实是 实例化的过,例如,类:EventToCommandBehavior,可绑定属性:EventName、Command
<Entry.Behaviors> <behaviors:EventToCommandBehavior EventName="TextChanged" Command="{Binding ValidateUserNameCommand}" /> </Entry.Behaviors>
3、xaml中定义一些按平台OnPlatform显示的资源值(Padding、Height)
<OnPlatform x:Key="GridPadding" x:TypeArguments="Thickness"> <On Platform="iOS" Value="20,0,10,15" /> <On Platform="Android, UWP, WinRT, WinPhone" Value="20,15,10,15" /> </OnPlatform> <OnPlatform x:Key="GridHeightRequest" x:TypeArguments="x:Double"> <On Platform="iOS" Value="135" /> <On Platform="Android, UWP, WinRT, WinPhone" Value="150" /> </OnPlatform> <OnPlatform x:Key="PaddingTop" x:TypeArguments="x:Double"> <On Platform="iOS" Value="0" /> <On Platform="Android, UWP, WinRT, WinPhone" Value="15" /> </OnPlatform> <OnPlatform x:Key="FirstRowHeight" x:TypeArguments="GridLength"> <On Platform="iOS" Value="65" /> <On Platform="Android, UWP, WinRT, WinPhone" Value="80" /> </OnPlatform> Padding="{StaticResource GridPadding}" HeightRequest="{StaticResource GridHeightRequest}" <Grid.RowDefinitions> <RowDefinition Height="{StaticResource FirstRowHeight}"/> <RowDefinition Height="30"/> <RowDefinition Height="40"/> </Grid.RowDefinitions>