【发布时间】:2018-08-26 00:06:32
【问题描述】:
我正在尝试在 XAML 中创建一个页面,其中包含两个 ToolbarItems,两个平台之间存在差异,但我的应用程序没有构建。我有“对象引用未设置为对象的实例”错误。
这是我的页面文件
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:prism="clr-namespace:Prism.Mvvm;assembly=Prism.Forms"
prism:ViewModelLocator.AutowireViewModel="True"
x:Class="VFood.Views.EntregadorEdit"
Title="{Binding Title}">
<ContentPage.ToolbarItems>
<OnPlatform x:TypeArguments="ToolbarItem">
<OnPlatform.iOS>
<ToolbarItem x:Name="SalvarItemIOS" Name="Done" Command="{Binding SalvarCommand}" Order="Primary" Priority="0"/>
<ToolbarItem x:Name="RemoveItemIOS" Name="Trash" Command="{Binding RemoveCommand}" Order="Primary" Priority="1"/>
</OnPlatform.iOS>
<OnPlatform.Android>
<ToolbarItem x:Name="SalvarItemDroid" Icon="ic_check" Command="{Binding SalvarCommand}" Order="Primary" Priority="0"/>
<ToolbarItem x:Name="RemoveItemDroid" Icon="ic_delete" Command="{Binding RemoveCommand}" Order="Primary" Priority="1"/>
</OnPlatform.Android>
</OnPlatform>
</ContentPage.ToolbarItems>
<ContentPage.Content>
<StackLayout Spacing="8">
<StackLayout.Padding>
<OnPlatform x:TypeArguments="Thickness" Android="16,16,16,16" iOS="10,10,10,10"/>
</StackLayout.Padding>
<Entry Placeholder="Nome" Text="{Binding Entregador.Nome}"/>
<Entry Placeholder="Telefone" Text="{Binding Entregador.Telefone}" Keyboard="Telephone" />
</StackLayout>
</ContentPage.Content>
</ContentPage>
如果我为每个平台评论一个工具栏项,就像下面的代码一样,构建就像一个魅力,但如果我尝试使用两个工具栏项进行构建,我就会出错。
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:prism="clr-namespace:Prism.Mvvm;assembly=Prism.Forms"
prism:ViewModelLocator.AutowireViewModel="True"
x:Class="VFood.Views.EntregadorEdit"
Title="{Binding Title}">
<ContentPage.ToolbarItems>
<OnPlatform x:TypeArguments="ToolbarItem">
<OnPlatform.iOS>
<!--<ToolbarItem x:Name="SalvarItemIOS" Name="Done" Command="{Binding SalvarCommand}" Order="Primary" Priority="0"/>-->
<ToolbarItem x:Name="RemoveItemIOS" Name="Trash" Command="{Binding RemoveCommand}" Order="Primary" Priority="1"/>
</OnPlatform.iOS>
<OnPlatform.Android>
<!--<ToolbarItem x:Name="SalvarItemDroid" Icon="ic_check" Command="{Binding SalvarCommand}" Order="Primary" Priority="0"/>-->
<ToolbarItem x:Name="RemoveItemDroid" Icon="ic_delete" Command="{Binding RemoveCommand}" Order="Primary" Priority="1"/>
</OnPlatform.Android>
</OnPlatform>
</ContentPage.ToolbarItems>
<ContentPage.Content>
<StackLayout Spacing="8">
<StackLayout.Padding>
<OnPlatform x:TypeArguments="Thickness" Android="16,16,16,16" iOS="10,10,10,10"/>
</StackLayout.Padding>
<Entry Placeholder="Nome" Text="{Binding Entregador.Nome}"/>
<Entry Placeholder="Telefone" Text="{Binding Entregador.Telefone}" Keyboard="Telephone" />
</StackLayout>
</ContentPage.Content>
</ContentPage>
【问题讨论】:
标签: xaml xamarin xamarin.forms prism