您好我创建了xamarin表单项目并实现了MasterDetailPage它运行良好,没有任何问题在android和ios,但我遇到UWP项目的Windows 10它抛出异常和应用程序崩溃。请找我的stacktrace
' System.ArgumentException'发生在Xamarin.Forms.Platform.UAP.dll
at Windows.Foundation.Size..ctor(Double width, Double height)
at Xamarin.Forms.Platform.UWP.MasterDetailControl.get_DetailSize()
at Xamarin.Forms.Platform.UWP.MasterDetailPageRenderer.UpdateBounds()
at Xamarin.Forms.Platform.UWP.MasterDetailPageRenderer.OnIsPaneOpenChanged(DependencyObject sender, DependencyProperty dp)
at Windows.UI.Xaml.DependencyObject.SetValue(DependencyProperty dp, Object value)
at Xamarin.Forms.Platform.UWP.MasterDetailPageRenderer.UpdateIsPresented()
at Xamarin.Forms.Platform.UWP.MasterDetailPageRenderer.OnElementPropertyChanged(Object sender, PropertyChangedEventArgs e)
at System.ComponentModel.PropertyChangedEventHandler.Invoke(Object sender, PropertyChangedEventArgs e)
at Xamarin.Forms.BindableObject.OnPropertyChanged(String propertyName)
at Xamarin.Forms.Element.OnPropertyChanged(String propertyName)
at Xamarin.Forms.BindableObject.SetValueActual(BindableProperty property, BindablePropertyContext context, Object value, Boolean currentlyApplying, SetValueFlags attributes, Boolean silent)
at Xamarin.Forms.BindableObject.SetValueCore(BindableProperty property, Object value, SetValueFlags attributes, SetValuePrivateFlags privateAttributes)
at Xamarin.Forms.MasterDetailPage.UpdateMasterBehavior(MasterDetailPage page)
我的代码
public class MasterHomePage : MasterDetailPage, MasterHomePageLisener
{
public MasterHomePage()
{
Title = AppRex.home;
Icon = "hamburger.png";
HomePageItem[] homePageItems =
{
new HomePageItem(AppRex.home, "home_icon.png", typeof(AfterLoginHomePage)),
new HomePageItem(AppRex.changePassword, "change_password_icon.png", typeof(ChangePassword)),
new HomePageItem("Set / Change PIN", "change_pin.png", typeof(LoginPinSetUpPage)),
new HomePageItem(AppRex.customerSuppoert, "support_icon.png", typeof(CustomerSupport)),
new HomePageItem(AppRex.about, "about_icon.png", typeof(AboutPage)),
new HomePageItem(AppRex.checkUpdate, "updates_icon.png", typeof(CheckUpdatedPage)),
new HomePageItem("Tutorial", "video_icon.png", typeof(TutorialVideoPage)),
new HomePageItem(AppRex.logout, "logout_icon.png", null),
};
this.Padding = new Thickness(0, Device.OnPlatform(20, 0, 0), 0, 0);
ListView list = new ListView
{
ItemsSource = homePageItems,
ItemTemplate = new DataTemplate(() =>
{
var imageCell = new LeftMenuCell();
imageCell.SetBinding(LeftMenuCell.TitleProperty, "Name");
imageCell.SetBinding(LeftMenuCell.ImageProperty, "IconSource");
return imageCell;
}),
VerticalOptions = LayoutOptions.FillAndExpand,
};
//Left menu
this.Master = new EgnatiumFull.Views.MyContentPage
{
Title = AppRex.home,
Content = new StackLayout { Children = { new Image() { Source = App.GetLogoImg()} ,
new MyLabel{Text = AppRex.version, HorizontalTextAlignment = TextAlignment.Center},
new MyLabel{Text = App.UserName, FontSize = 24, FontAttributes= FontAttributes.Bold},
new MyLabel{Text = App.UserEmailId},
new BoxView { BackgroundColor = Color.Gray, HeightRequest = 1}, list }
}
};
this.Detail = new AfterLoginHomePage(this);
if (Device.OS == TargetPlatform.WinPhone)
{
(this.Detail as EgnatiumFull.Views.MyContentPage).Content.GestureRecognizers.Add(
new TapGestureRecognizer((view) =>
{
this.IsPresented = true;
}));
}
// Define a selected handler for the ListView.
list.ItemTapped += async(sender, args) =>
{
var homePageItem = ((HomePageItem)args.Item);
var type = homePageItem.TargetType;
if (type == null)
{
if (homePageItem.Name.Equals(AppRex.logout))
{
list.SelectedItem = null;
var resp = await DisplayAlert("","Are you sure want to Logout?","Yes", "No");
if (resp)
{
await App.UpdateLoginStatus(true);
Application.Current.MainPage = App.GetPage();
}
}
}
else {
Page page = null;
if (type.Equals(typeof(AfterLoginHomePage)))
{
page = new AfterLoginHomePage(this);
}
else if (type.Equals(typeof(AboutPage)))
{
page = new AboutPage(this);
}
else if (type.Equals(typeof(ChangePassword)))
{
page = new ChangePassword(this);
}
else if (type.Equals(typeof(LoginPinSetUpPage)))
{
page = new LoginPinSetUpPage(App.UserId, App.UserEmailId, this);
}
else if (type.Equals(typeof(TutorialVideoPage)))
{
page = new TutorialVideoPage(this);
}
else if (type.Equals(typeof(CustomerSupport)))
{
page = new CustomerSupport(this);
}
else if (type.Equals(typeof(CheckUpdatedPage)))
{
page = new CheckUpdatedPage(this);
}
page.Title = ((HomePageItem)args.Item).Name;
Detail = page;
}
// Show the detail page.
this.IsPresented = false;
((ListView)sender).SelectedItem = null;
};
// Initialize the ListView selection.
//list.SelectedItem = homePageItems[0];
}
public void HomeIconClicked()
{
this.Detail = new AfterLoginHomePage(this);
}
public void MenuIconClicked()
{
this.IsPresented = !this.IsPresented;
}
}
public interface MasterHomePageLisener
{
void MenuIconClicked();
void HomeIconClicked();
}