[英]Using MasterDetailPage or ToolbarItem throws exception on Xamarin.Forms
Xamarin.Forms可移植庫XAML項目中有以下兩個XAML代碼:
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="TestApp.Views.TestView">
<ContentPage.ToolbarItems>
<ToolbarItem Text="{Binding ToolbarItemText}" Command="{Binding ToolbarItemCommand}" Order="Default" Priority="0"/>
</ContentPage.ToolbarItems>
<ContentPage.Content>
</ContentPage.Content>
</ContentPage>
和
<MasterDetailPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="TestApp.Views.Test2View">
<MasterDetailPage.Master>
<ContentPage Title="Currencies">
</ContentPage>
</MasterDetailPage.Master>
<MasterDetailPage.Detail>
<NavigationPage>
<x:Arguments>
<ContentPage>
</ContentPage>
</x:Arguments>
</NavigationPage>
</MasterDetailPage.Detail>
</MasterDetailPage>
運行Windows Phone 8.1項目(WinRT,而不是Silverlight)時,我有以下異常:
E_UNKNOWN_ERROR
錯誤HRESULT E_FAIL已從對COM組件的調用返回。
問題是,你必須指定MasterDetailPage.Master頁,而該ToolbarIcon的圖標路徑 。 此外,對於MasterDetailPage.Master頁面,您必須指定Title屬性。
這是更正的代碼示例:
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="TestApp.Views.TestView">
<ContentPage.ToolbarItems>
<ToolbarItem Text="{Binding ToolbarItemText}" Command="{Binding ToolbarItemCommand}" Order="Default" Priority="0">
<ToolbarItem.Icon>
<OnPlatform x:TypeArguments="FileImageSource"
Android="my-icon"
WinPhone="Assets/my-icon.png" />
</ToolbarItem.Icon>
</ToolbarItem>
</ContentPage.ToolbarItems>
<ContentPage.Content>
</ContentPage.Content>
</ContentPage>
和
<MasterDetailPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="TestApp.Views.Test2View">
<MasterDetailPage.Master>
<ContentPage Title="Currencies">
<ContentPage.Icon>
<OnPlatform x:TypeArguments="FileImageSource"
Android="my-icon"
WinPhone="Assets/my-icon.png" />
</ContentPage.Icon>
</ContentPage>
</MasterDetailPage.Master>
<MasterDetailPage.Detail>
<NavigationPage>
<x:Arguments>
<ContentPage>
</ContentPage>
</x:Arguments>
</NavigationPage>
</MasterDetailPage.Detail>
</MasterDetailPage>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.