Add few things

main
DJYohann 2 years ago
parent d5b5dc34af
commit ca1000d0c6

@ -1,5 +1,4 @@
using System;
using System.Globalization;
using System.Globalization;
namespace App.Converters
{
@ -13,8 +12,7 @@ namespace App.Converters
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
var bytes = System.Convert.FromBase64String(value as string);
MemoryStream imageDecode = new MemoryStream(bytes);
return ImageSource.FromStream(() => imageDecode);
return ImageSource.FromStream(() => new MemoryStream(bytes));
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)

@ -23,8 +23,10 @@ public static class MauiProgram
})
.Services.AddSingleton<IDataManager, StubData>()
.AddSingleton<ChampionListPageVM>()
.AddTransient<ChampionDetailPageVM>()
.AddSingleton<ChampionManagerVM>()
.AddSingleton<ChampionsListPage>();
.AddSingleton<ChampionsListPage>()
.AddSingleton<ChampionDetailPage>();
#if DEBUG
builder.Logging.AddDebug();

@ -5,6 +5,11 @@
xmlns:converters="clr-namespace:App.Converters"
Title="Add Champion"
BackgroundColor="Black">
<ContentPage.ToolbarItems>
<ToolbarItem Text="Edit" Command="{Binding NavigateToChampionEditPageCommand}"/>
<ToolbarItem Text="Edit" Command="{Binding NavigateToChampionEditPageCommand}"/>
</ContentPage.ToolbarItems>
<ContentPage.Resources>
<converters:Base64ToImage x:Key="Base64ToImageConv"/>
@ -28,7 +33,7 @@
<Entry Placeholder="Champion name"/>
</StackLayout>
<StackLayout Orientation="Horizontal" VerticalOptions="CenterAndExpand">
<!--<StackLayout Orientation="Horizontal" VerticalOptions="CenterAndExpand">
<Label Text="Icon"/>
</StackLayout>
@ -36,7 +41,7 @@
<StackLayout Orientation="Horizontal" VerticalOptions="CenterAndExpand">
<Label Text="Image"/>
</StackLayout>
</StackLayout>-->
<StackLayout Orientation="Horizontal" VerticalOptions="CenterAndExpand">
<Label Text="Bio"/>

@ -4,6 +4,7 @@ public partial class ChampionAddEditPage : ContentPage
{
public ChampionAddEditPage()
{
InitializeComponent();
}
}

@ -6,8 +6,8 @@
Title="Champion Page"
BackgroundColor="Black">
<ContentPage.ToolbarItems>
<ToolbarItem Text="Edit" Clicked="ToolbarItem_Clicked"/>
<ToolbarItem Text="Edit"
Command="{Binding NaviagteToChampionAddEditPageCommand}"/>
</ContentPage.ToolbarItems>
<ContentPage.Resources>
@ -20,23 +20,23 @@
<ScrollView>
<StackLayout Orientation="Vertical">
<Image Source="{Binding Path=Image, Converter={StaticResource Base64ToImageConv}}"/>
<Image Source="{Binding Path=ChampionVM.Image, Converter={StaticResource Base64ToImageConv}}"/>
<StackLayout Orientation="Horizontal" Padding="0,0,0,20">
<Label Text="{Binding Name}"
<Label Text="{Binding ChampionVM.Name}"
HorizontalOptions="Start"
FontSize="Title"/>
<Image HorizontalOptions="End"/>
</StackLayout>
<Label Text="{Binding Bio}"/>
<Label Text="{Binding ChampionVM.Bio}"/>
<Label Text="Characteristics"
FontSize="Title"
Padding="0,0,0,20"/>
<CollectionView ItemsSource="{Binding Characteristics}"
<CollectionView ItemsSource="{Binding ChampionVM.Characteristics}"
ItemsLayout="VerticalGrid, 3">
<CollectionView.ItemTemplate>
<DataTemplate>

@ -1,20 +1,26 @@
using ViewModel;
using App.ViewModel;
using ViewModel;
namespace App.Pages;
public partial class ChampionDetailPage : ContentPage
{
public ChampionVM ChampionVM { get; private set; }
#region Properties
public ChampionDetailPage()
public ChampionDetailPageVM ChampionDetailPageVM { get; private set; }
public ChampionManagerVM ChampionManagerVM { get; private set; }
public ChampionVM ChampionVM { get; private set; }
#endregion
public ChampionDetailPage(ChampionDetailPageVM championDetailPageVM, ChampionManagerVM championManagerVM)
{
//ChampionVM = championVM;
InitializeComponent();
BindingContext = ChampionVM;
}
ChampionDetailPageVM = championDetailPageVM;
ChampionManagerVM = championManagerVM;
ChampionVM = ChampionManagerVM.SelectedChampion;
async void ToolbarItem_Clicked(System.Object sender, System.EventArgs e)
{
await Navigation.PushModalAsync(new ChampionAddEditPage());
ChampionDetailPageVM.Navigation = Navigation;
InitializeComponent();
BindingContext = this;
}
}
}

@ -6,12 +6,17 @@
x:Class="App.Pages.ChampionsListPage"
Title="Champions">
<ContentPage.ToolbarItems>
<ToolbarItem Text="Add" Command="{Binding NaviagteToChampionAddEditPageCommand}"/>
<ToolbarItem Text="Add"
Command="{Binding NaviagteToChampionAddEditPageCommand}"/>
</ContentPage.ToolbarItems>
<ContentPage.Resources>
<converters:Base64ToImage x:Key="Base64ToImageConv"/>
<ResourceDictionary>
<toolkit:SelectedItemEventArgsConverter x:Key="SelectedItemEventArgsConverter" />
</ResourceDictionary>
<Style TargetType="Button">
<Setter Property="WidthRequest">40</Setter>
<Setter Property="HeightRequest">20</Setter>
@ -29,10 +34,11 @@
SelectionMode="Single">
<ListView.Behaviors>
<toolkit:EventToCommandBehavior
x:TypeArguments="SelectedItemChangedEventArgs"
EventName="ItemSelected"
Command="{Binding NavigateToChampionDetailCommand}"/>
</ListView.Behaviors>
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
@ -40,25 +46,24 @@
<SwipeView.RightItems>
<SwipeItems>
<SwipeItem Text="Delete"
BackgroundColor="{StaticResource DeleteColor}"/>
BackgroundColor="{StaticResource DeleteColor}"
IsDestructive="True"/>
<SwipeItem Text="Edit"
BackgroundColor="{StaticResource EditColor}"/>
BackgroundColor="{StaticResource EditColor}"
Command="{Binding NaviagteToChampionAddEditPageCommand}"
CommandParameter="{Binding .}"/>
</SwipeItems>
</SwipeView.RightItems>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="3*"/>
</Grid.ColumnDefinitions>
<SwipeView.Content>
<StackLayout Orientation="Horizontal" Padding="10">
<Image Source="{Binding Path=Icon, Converter={StaticResource Base64ToImageConv}}"/>
<Image Grid.Column="0" Source="{Binding Path=Icon, Converter={StaticResource Base64ToImageConv}}"/>
<StackLayout Grid.Column="1">
<Label Text="{Binding Name}"/>
<StackLayout Grid.Column="1">
<Label Text="{Binding Name}"/>
</StackLayout>
</StackLayout>
</Grid>
</SwipeView.Content>
</SwipeView>
</ViewCell>
</DataTemplate>

@ -1,5 +1,4 @@
using ViewModel;
using App.ViewModel;
using App.ViewModel;
namespace App.Pages;
@ -10,8 +9,8 @@ public partial class ChampionsListPage : ContentPage
public ChampionsListPage(ChampionListPageVM championListPageVM)
{
ChampionListPageVM = championListPageVM;
ChampionListPageVM.Navigation = this.Navigation;
ChampionListPageVM.Navigation = Navigation;
InitializeComponent();
BindingContext = ChampionListPageVM;
}
}
}

@ -0,0 +1,31 @@
using System;
using System.Windows.Input;
using ViewModel;
using App.Pages;
namespace App.ViewModel
{
public class ChampionDetailPageVM
{
#region Properties
public INavigation Navigation { get; set; }
#endregion
#region Commands
public ICommand NaviagteToChampionAddEditPageCommand { get; private set; }
#endregion
public ChampionDetailPageVM()
{
NaviagteToChampionAddEditPageCommand = new Command(
execute: async () => await Navigation.PushModalAsync(new ChampionAddEditPage()),
canExecute: () => Navigation is not null
);
}
}
}

@ -1,5 +1,4 @@
using System;
using System.Windows.Input;
using System.Windows.Input;
using App.Pages;
using ViewModel;
@ -7,27 +6,37 @@ namespace App.ViewModel
{
public class ChampionListPageVM
{
public INavigation Navigation { get; set; }
#region Properties
public ChampionManagerVM ChampionManagerVM { get; private set; }
public INavigation Navigation { get; set; }
public ChampionManagerVM ChampionManagerVM { get; private set; }
public ICommand NavigateToChampionDetailCommand { get; private set; }
public ICommand NaviagteToChampionAddEditPageCommand { get; private set; }
#endregion
#region Commands
public ICommand NavigateToChampionDetailCommand { get; private set; }
public ICommand NaviagteToChampionAddEditPageCommand { get; private set; }
#endregion
public ChampionListPageVM(ChampionManagerVM championManager)
{
ChampionManagerVM = championManager;
{
ChampionManagerVM = championManager;
NavigateToChampionDetailCommand = new Command (
execute: async () => await Shell.Current.GoToAsync(nameof(ChampionDetailPage)),
canExecute: () => ChampionManagerVM is not null
);
NavigateToChampionDetailCommand = new Command<ChampionVM>(
execute: async (selectedChampion) =>
{
ChampionManagerVM.SelectedChampion = selectedChampion;
await Shell.Current.GoToAsync(nameof(ChampionDetailPage));
},
canExecute: (selectedChampion) => ChampionManagerVM is not null && selectedChampion is not null
);
NaviagteToChampionAddEditPageCommand = new Command(
execute: async () => await Navigation.PushModalAsync(new ChampionAddEditPage()),
canExecute: () => ChampionManagerVM is not null
NaviagteToChampionAddEditPageCommand = new Command<ChampionVM>(
execute: async (selectedChampion) => await Navigation.PushModalAsync(new ChampionAddEditPage()),
canExecute: (selectedChampion) => ChampionManagerVM is not null && Navigation is not null
);
}
}
}
}
}

@ -42,6 +42,8 @@ namespace ViewModel
public int Count { get; set; } = 5;
public ChampionVM SelectedChampion { get; set; }
#endregion
#region Commands

Loading…
Cancel
Save