Refactor Menu

This commit is contained in:
2019-03-25 22:01:27 +01:00
parent e64979e42f
commit c96e8fc6ce
5 changed files with 19 additions and 39 deletions

View File

@@ -30,16 +30,19 @@ namespace PlantBox.Client.Forms
if (e.Item is MenuPageItem item) if (e.Item is MenuPageItem item)
{ {
IsPresented = false; IsPresented = false;
var page = item.PageCreator(); var page = item.Page;
page.Title = item.Title;
if (Detail.Navigation.NavigationStack.Count > 1) if (Detail.Navigation.NavigationStack.Count > 1 || page == null)
{ {
await Detail.Navigation.PopToRootAsync(); await Detail.Navigation.PopToRootAsync();
} }
if (page != null)
{
page.Title = item.Title;
await Detail.Navigation.PushAsync(page); await Detail.Navigation.PushAsync(page);
} }
} }
} }
} }
}

View File

@@ -22,8 +22,9 @@ namespace PlantBox.Client.Forms
items.ItemsSource = new MenuPageItem[] items.ItemsSource = new MenuPageItem[]
{ {
new MenuPageItem(Locale.Settings, ImageResourceExtension.GetImage("Settings.png"), typeof(SettingsPage)), new MenuPageItem(Locale.HomePageTitle, ImageResourceExtension.GetImage("Home.png"), null),
new MenuPageItem(Locale.About, ImageResourceExtension.GetImage("Info.png"), typeof(AboutPage)) new MenuPageItem(Locale.Settings, ImageResourceExtension.GetImage("Settings.png"), new SettingsPage()),
new MenuPageItem(Locale.About, ImageResourceExtension.GetImage("Info.png"), new AboutPage())
}; };
} }
} }

View File

@@ -11,41 +11,15 @@ namespace PlantBox.Client.Models
{ {
public event PropertyChangedEventHandler PropertyChanged; public event PropertyChangedEventHandler PropertyChanged;
private ImageSource _image; public ImageSource Image { get; }
public ImageSource Image public string Title { get; }
{ public Page Page { get; }
get => _image;
set
{
if (value != _image)
{
_image = value;
OnPropertyChanged(nameof(Image));
}
}
}
private string _title; public MenuPageItem(string title, ImageSource image, Page targetPage)
public string Title
{ {
get => _title; Image = image;
set Title = title;
{ Page = targetPage;
if (value != _title)
{
_title = value;
OnPropertyChanged(nameof(Title));
}
}
}
public Func<Page> PageCreator { get; }
public MenuPageItem(string title, ImageSource image, Type targetPage)
{
_image = image;
_title = title;
PageCreator = () => (Page)Activator.CreateInstance(targetPage);
} }
public void OnPropertyChanged([CallerMemberName] string propertyName = null) public void OnPropertyChanged([CallerMemberName] string propertyName = null)

View File

@@ -14,6 +14,7 @@
<ItemGroup> <ItemGroup>
<None Remove="Resources\Images\Banner.png" /> <None Remove="Resources\Images\Banner.png" />
<None Remove="Resources\Images\Help.png" /> <None Remove="Resources\Images\Help.png" />
<None Remove="Resources\Images\Home.png" />
<None Remove="Resources\Images\Info.png" /> <None Remove="Resources\Images\Info.png" />
<None Remove="Resources\Images\Logo_Gray.png" /> <None Remove="Resources\Images\Logo_Gray.png" />
<None Remove="Resources\Images\Settings.png" /> <None Remove="Resources\Images\Settings.png" />
@@ -22,6 +23,7 @@
<ItemGroup> <ItemGroup>
<EmbeddedResource Include="Resources\Images\Banner.png" /> <EmbeddedResource Include="Resources\Images\Banner.png" />
<EmbeddedResource Include="Resources\Images\Help.png" /> <EmbeddedResource Include="Resources\Images\Help.png" />
<EmbeddedResource Include="Resources\Images\Home.png" />
<EmbeddedResource Include="Resources\Images\Info.png" /> <EmbeddedResource Include="Resources\Images\Info.png" />
<EmbeddedResource Include="Resources\Images\Logo_Gray.png" /> <EmbeddedResource Include="Resources\Images\Logo_Gray.png" />
<EmbeddedResource Include="Resources\Images\Settings.png" /> <EmbeddedResource Include="Resources\Images\Settings.png" />

Binary file not shown.

After

Width:  |  Height:  |  Size: 279 B