Created
July 22, 2016 08:35
-
-
Save joacar/28495d9cae5b9114056e202a00f957d1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace Main | |
{ | |
public partial class MainView : MasterDetailPage | |
{ | |
public MainView() | |
{ | |
InitializeComponent(); | |
Detail = new NavigationPage(new StartView()) | |
{ | |
BindingContext = new StartViewModel() | |
}; | |
Master = new MainMenuView(); | |
} | |
} | |
public partial class StartView | |
{ | |
public StartView() | |
{ | |
InitializeComponent(); | |
} | |
private void Button_OnClicked(object sender, EventArgs e) | |
{ | |
var page = new ContentPage | |
{ | |
Content = new StackLayout() | |
{ | |
Children = | |
{ | |
new Label() | |
{ | |
Text = "I am content page" | |
} | |
} | |
}, | |
Title = "ContentPage" | |
}; | |
Navigation.PushAsync(page, true); | |
} | |
} | |
public interface IView | |
{ | |
string Title { get; } | |
string Subtitle { get; } | |
} | |
public class StartViewModel : IView | |
{ | |
public StartViewModel() | |
{ | |
Title = "Start title"; | |
Subtitle = "Start sub title"; | |
} | |
} | |
} | |
using System.ComponentModel; | |
using Clistr.Droid.Renderers; | |
using Clistr.Infrastructure; | |
using Xamarin.Forms; | |
using Xamarin.Forms.Platform.Android; | |
using Xamarin.Forms.Platform.Android.AppCompat.NavigationPageRenderer; | |
using Android.Support.V7.Widget.Toolbar; | |
[assembly: ExportRenderer(typeof(NavigationPage), typeof(NavigationPageRenderer))] | |
namespace Main | |
{ | |
public class NavigationPageRenderer : NavigationRenderer | |
{ | |
private Toolbar toolbar; | |
protected override void OnElementChanged(ElementChangedEventArgs<NavigationPage> e) | |
{ | |
base.OnElementChanged(e); | |
SetCustomView(e.NewElement.CurrentPage.BindingContext as IView); | |
} | |
private void SetCustomView(IView view) | |
{ | |
toolbar.Subtitle = view?.Subtitle ?? string.Empty; | |
} | |
protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e) | |
{ | |
base.OnElementPropertyChanged(sender, e); | |
if (e.PropertyName.Equals("CurrentPage")) | |
{ | |
SetCustomView(((NavigationPage)sender).CurrentPage.BindingContext as IView); | |
} | |
} | |
public override void OnViewAdded(Android.Views.View child) | |
{ | |
base.OnViewAdded(child); | |
if (child.GetType() == typeof(Toolbar)) | |
{ | |
toolbar = (Toolbar)child; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment