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,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);
}
}
}
}

View File

@@ -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())
};
}
}

View File

@@ -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<Page> 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)

View File

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

Binary file not shown.

After

Width:  |  Height:  |  Size: 279 B