我正在将Auth0与Xamarin Forms PCL Library一起使用。 我有以下MainPage类:
public App ()
{
Current = this;
Login ();
}
public void ShowMainPage ()
{
MainPage = new MainPage ();
}
public async void Login ()
{
await DependencyService.Get<IAuth0WidgetLogin>().LoginUseAuth0EmbeddedWidget();
App.Current.Properties["IsLoggedIn"] = true;
ShowMainPage ();
}
在Application class
中关注public class MenuPage : ContentPage
{
MasterDetailPage master;
TableView tableView;
public MenuPage ()
{
Title = "LoginPattern";
Icon = "slideout.png";
var section = new TableSection () {
new TextCell {Text = "Sessions"},
new TextCell {Text = "Speakers"},
new TextCell {Text = "Favorites"},
new TextCell {Text = "Room Plan"},
new TextCell {Text = "Map"},
};
var root = new TableRoot () {section} ;
tableView = new TableView ()
{
Root = root,
Intent = TableIntent.Menu,
};
var logoutButton = new Button { Text = "Logout" };
logoutButton.Clicked += (sender, e) => {
App.Current.Logout();
};
Content = new StackLayout {
BackgroundColor = Color.Gray,
VerticalOptions = LayoutOptions.FillAndExpand,
Children = {
tableView,
logoutButton
}
};
}
}
public class DetailPage : ContentPage
{
public DetailPage ()
{
BackgroundColor = new Color (0, 0, 1, 0.2);
var text = "Slide > to see the master / menu";
if (Device.OS == TargetPlatform.Android) {
text = @"Click the action bar dots to see the master / menu";
} else if (Device.OS == TargetPlatform.WinPhone) {
text = @"Click button \/ to see the master / menu ";
}
Content = new StackLayout {
HorizontalOptions = LayoutOptions.Center,
Padding = new Thickness (10, 40, 10, 10),
Children = {
new Label { Text = text }
}
};
}
}
因此,在登录时,我最初我没有加载除Auth0登录窗口小部件之外的任何页面。成功登录后,我想显示MasterDetailPage。但是我收到以下错误: Java.Lang.IllegalArgumentException:必须使用MeasureSpec.EXACTLY测量DrawerLayout。
请告知我是否需要在NavigationPage中加载Widget以及如何操作。
编辑17/7:
{{1}}
答案 0 :(得分:2)
我会尝试做两件事:
答案 1 :(得分:1)
只是为了帮助他人,以下是我的最终解决方案:
public class MainPage : MasterDetailPage
{
public MainPage ()
{
Master = new MenuPage (this);
Detail = new DetailPage ();
ShowLoginDialog ();
}
async void ShowLoginDialog()
{
var page = new LoginPage();
await Navigation.PushModalAsync(page);
App.Current.Login ();
await Navigation.PopModalAsync();
}
}
PS:LoginPage只是一个空的ContentPage。