0
経由でログインした後、私はFacebook経由のログインが必要ですxamarin.formsクロスプラットフォームを使用してモバイルアプリを作成していたユーザは、サイド、サインインした後、ホームページに向けられているとき、私はしかし、この作業を得ました私がコード化したメニューは表示されません。代わりにタブバーに戻るための左矢印が表示されますが、これは意味を持ちません。これについての助けに感謝します、ありがとう。Xamarin.formsホームページのFacebook
ドロイドプロジェクト
[assembly: ExportRenderer(typeof(Login), typeof(loyaltyworx1.Droid.FacebookRender))]
namespace loyaltyworx1.Droid
{
public class FacebookRender : PageRenderer
{
public FacebookRender()
{
var activity = this.Context as Activity;
var auth = new OAuth2Authenticator(
clientId: "",
scope: "",
authorizeUrl: new Uri("https://www.facebook.com/dialog/oauth/"),
redirectUrl: new Uri("https://www.facebook.com/connect/login_success.html")
);
auth.Completed += async (sender, eventArgs) =>
{
if (eventArgs.IsAuthenticated)
{
var accessToken = eventArgs.Account.Properties["access_token"].ToString();
var expiresIn = Convert.ToDouble(eventArgs.Account.Properties["expires_in"]);
var expiryDate = DateTime.Now + TimeSpan.FromSeconds(expiresIn);
var request = new OAuth2Request("GET", new Uri("https://graph.facebook.com/me"), null, eventArgs.Account);
var response = await request.GetResponseAsync();
var obj = JObject.Parse(response.GetResponseText());
var id = obj["id"].ToString().Replace("\"", "");
var name = obj["name"].ToString().Replace("\"", "");
await App.NavigateToProfile(string.Format("Hello {0}", name));
}
else
{
await App.NavigateToProfile("Invalid Login");
}
};
activity.StartActivity(auth.GetUI(activity));
}
}
}
App.csでFacebookRenderクラス
public App()
{
InitializeComponent();
MainPage = new NavigationPage(new MainPage());
}
public async static Task NavigateToProfile(string message)
{
await App.Current.MainPage.Navigation.PushAsync(new Profile(message));
}
MainPage.xaml.cs
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
}
private async void LoginBtn_Clicked(object sender, EventArgs e)
{
await Navigation.PushAsync(new Login());
}
}
Login.xaml.cs
public partial class Login : MasterDetailPage
{
public List<MasterPageItem> menuList { get; set; }
public Login()
{
InitializeComponent();
menuList = new List<MasterPageItem>();
var page1 = new MasterPageItem() { Title = "Item 1", Icon = "home.png", TargetType = typeof(Page1) };
var page2 = new MasterPageItem() { Title = "Item 2", Icon = "settings.png", TargetType = typeof(Page2) };
var page3 = new MasterPageItem() { Title = "Item 3", Icon = "home.png", TargetType = typeof(Page1) };
var page4 = new MasterPageItem() { Title = "Item 4", Icon = "settings.png", TargetType = typeof(Page2) };
menuList.Add(page1);
menuList.Add(page2);
navigationDrawerList.ItemsSource = menuList;
Detail = new NavigationPage((Page)Activator.CreateInstance(typeof(Page1)));
}
private void OnMenuItemSelected(object sender, SelectedItemChangedEventArgs e)
{
var item = (MasterPageItem)e.SelectedItem;
Type page = item.TargetType;
Detail = new NavigationPage((Page)Activator.CreateInstance(page));
IsPresented = false;
}
}
Login.xaml
<?xml version="1.0" encoding="utf-8" ?>
<MasterDetailPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="loyaltyworx1.Login">
<MasterDetailPage.Master>
<ContentPage Title="Menu"
BackgroundColor="#e8e8e8">
<StackLayout Orientation="Vertical">
<!--
This StackLayout you can use for other
data that you want to have in your menu drawer
-->
<StackLayout BackgroundColor="#e74c3c"
HeightRequest="100">
<Label Text="Menu"
FontSize="20"
VerticalOptions="CenterAndExpand"
TextColor="White"
HorizontalOptions="Center"/>
</StackLayout>
<ListView x:Name="navigationDrawerList"
RowHeight="60"
SeparatorVisibility="None"
BackgroundColor="#e8e8e8"
ItemSelected="OnMenuItemSelected">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<!-- Main design for our menu items -->
<StackLayout VerticalOptions="FillAndExpand"
Orientation="Horizontal"
Padding="20,10,0,10"
Spacing="20">
<Image Source="{Binding Icon}"
WidthRequest="40"
HeightRequest="40"
VerticalOptions="Center" />
<Label Text="{Binding Title}"
FontSize="Medium"
VerticalOptions="Center"
TextColor="Black"/>
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</StackLayout>
</ContentPage>
</MasterDetailPage.Master>
<MasterDetailPage.Detail>
<NavigationPage>
</NavigationPage>
</MasterDetailPage.Detail>
</MasterDetailPage>
コードの多くは、ここで読むことを。あなたがいない 'Navigate'機能を使用するために、全体の内容を交換する必要があります(' MainPage.Contet = yourNavigationPage') – Alex
申し訳ありませんが、私は理解しません –