From c96e8fc6ce577c08af1f42f1cd388b91d7506706 Mon Sep 17 00:00:00 2001 From: Eveldee Date: Mon, 25 Mar 2019 22:01:27 +0100 Subject: [PATCH] Refactor Menu --- .../PlantBox.Client/Forms/MainPage.xaml.cs | 11 +++-- .../PlantBox.Client/Forms/MenuPage.xaml.cs | 5 ++- .../PlantBox.Client/Models/MenuPageItem.cs | 40 +++--------------- .../PlantBox.Client/PlantBox.Client.csproj | 2 + .../PlantBox.Client/Resources/Images/Home.png | Bin 0 -> 279 bytes 5 files changed, 19 insertions(+), 39 deletions(-) create mode 100644 PlantBox.Client/PlantBox.Client/Resources/Images/Home.png diff --git a/PlantBox.Client/PlantBox.Client/Forms/MainPage.xaml.cs b/PlantBox.Client/PlantBox.Client/Forms/MainPage.xaml.cs index 7215bbf..b5c6d76 100644 --- a/PlantBox.Client/PlantBox.Client/Forms/MainPage.xaml.cs +++ b/PlantBox.Client/PlantBox.Client/Forms/MainPage.xaml.cs @@ -30,15 +30,18 @@ namespace PlantBox.Client.Forms if (e.Item is MenuPageItem item) { IsPresented = false; - var page = item.PageCreator(); - page.Title = item.Title; + var page = item.Page; - if (Detail.Navigation.NavigationStack.Count > 1) + if (Detail.Navigation.NavigationStack.Count > 1 || page == null) { await Detail.Navigation.PopToRootAsync(); } - await Detail.Navigation.PushAsync(page); + if (page != null) + { + page.Title = item.Title; + await Detail.Navigation.PushAsync(page); + } } } } diff --git a/PlantBox.Client/PlantBox.Client/Forms/MenuPage.xaml.cs b/PlantBox.Client/PlantBox.Client/Forms/MenuPage.xaml.cs index f8a4f26..0a24218 100644 --- a/PlantBox.Client/PlantBox.Client/Forms/MenuPage.xaml.cs +++ b/PlantBox.Client/PlantBox.Client/Forms/MenuPage.xaml.cs @@ -22,8 +22,9 @@ namespace PlantBox.Client.Forms items.ItemsSource = new MenuPageItem[] { - new MenuPageItem(Locale.Settings, ImageResourceExtension.GetImage("Settings.png"), typeof(SettingsPage)), - new MenuPageItem(Locale.About, ImageResourceExtension.GetImage("Info.png"), typeof(AboutPage)) + new MenuPageItem(Locale.HomePageTitle, ImageResourceExtension.GetImage("Home.png"), null), + new MenuPageItem(Locale.Settings, ImageResourceExtension.GetImage("Settings.png"), new SettingsPage()), + new MenuPageItem(Locale.About, ImageResourceExtension.GetImage("Info.png"), new AboutPage()) }; } } diff --git a/PlantBox.Client/PlantBox.Client/Models/MenuPageItem.cs b/PlantBox.Client/PlantBox.Client/Models/MenuPageItem.cs index 1a91204..6c1065f 100644 --- a/PlantBox.Client/PlantBox.Client/Models/MenuPageItem.cs +++ b/PlantBox.Client/PlantBox.Client/Models/MenuPageItem.cs @@ -11,41 +11,15 @@ namespace PlantBox.Client.Models { public event PropertyChangedEventHandler PropertyChanged; - private ImageSource _image; - public ImageSource Image - { - get => _image; - set - { - if (value != _image) - { - _image = value; - OnPropertyChanged(nameof(Image)); - } - } - } + public ImageSource Image { get; } + public string Title { get; } + public Page Page { get; } - private string _title; - public string Title + public MenuPageItem(string title, ImageSource image, Page targetPage) { - get => _title; - set - { - if (value != _title) - { - _title = value; - OnPropertyChanged(nameof(Title)); - } - } - } - - public Func PageCreator { get; } - - public MenuPageItem(string title, ImageSource image, Type targetPage) - { - _image = image; - _title = title; - PageCreator = () => (Page)Activator.CreateInstance(targetPage); + Image = image; + Title = title; + Page = targetPage; } public void OnPropertyChanged([CallerMemberName] string propertyName = null) diff --git a/PlantBox.Client/PlantBox.Client/PlantBox.Client.csproj b/PlantBox.Client/PlantBox.Client/PlantBox.Client.csproj index bceb626..f639f32 100644 --- a/PlantBox.Client/PlantBox.Client/PlantBox.Client.csproj +++ b/PlantBox.Client/PlantBox.Client/PlantBox.Client.csproj @@ -14,6 +14,7 @@ + @@ -22,6 +23,7 @@ + diff --git a/PlantBox.Client/PlantBox.Client/Resources/Images/Home.png b/PlantBox.Client/PlantBox.Client/Resources/Images/Home.png new file mode 100644 index 0000000000000000000000000000000000000000..134aafdcc199b75577636aae32daaf7cfc7572f1 GIT binary patch literal 279 zcmV+y0qFjTP)!p)Jo=gfBZL@HfbdF8(X%Nf0;@7dFU_eCP@OeOw4zQR5j*sz9T5TaIHC_7>5@~- z1vxqslf!@;a>tDUo`xu8LozEeK^YoTB!eg(c^