Navigation command

master
Mathis RIBEMONT 1 year ago
parent 8fc0bd8214
commit 7a08f6bb11

@ -52,6 +52,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="CommunityToolkit.Maui" Version="5.2.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="7.0.0" />
</ItemGroup>

@ -3,6 +3,7 @@ using VM;
using Microsoft.Extensions.Logging;
using Model;
using StubLib;
using CommunityToolkit.Maui;
namespace ClientMAUI
{
@ -13,6 +14,7 @@ namespace ClientMAUI
var builder = MauiApp.CreateBuilder();
builder
.UseMauiApp<App>()
.UseMauiCommunityToolkit()
.ConfigureFonts(fonts =>
{
fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");

@ -1,9 +1,4 @@
using Microsoft.Maui.Controls;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ClientMAUI.Views.Pages;
using System.Windows.Input;
using VM;
@ -13,10 +8,19 @@ namespace ClientMAUI.VMApp
{
public DataManagerVM DataManagerVM { get; private set; }
public ICommand ItemTappedCommand { get; private set; }
private INavigation _navigation;
public ChampionListPageVM(DataManagerVM dataManager)
public ChampionListPageVM(DataManagerVM dataManager, INavigation navigaton)
{
DataManagerVM = dataManager;
_navigation = navigaton;
ItemTappedCommand = new Command(
async (object item) =>
{
await _navigation.PushAsync(new ChampionDetail(item as ChampionVM));
});
}
}
}

@ -3,12 +3,19 @@
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="ClientMAUI.Views.Pages.ChampionListPage"
xmlns:converters="clr-namespace:ClientMAUI.Converters"
xmlns:toolkit="http://schemas.microsoft.com/dotnet/2022/maui/toolkit"
Title="Champions">
<ContentPage.Resources>
<converters:Base64ToImageSourceConverter x:Key="Base64ToImageSource"/>
<toolkit:ItemTappedEventArgsConverter x:Key="ItemTappedEventArgsConverter" />
</ContentPage.Resources>
<VerticalStackLayout>
<ListView ItemsSource="{Binding DataManagerVM.ChampionVMs}" ItemTapped="ListView_ItemTapped" SelectionMode="Single" RowHeight="75">
<ListView ItemsSource="{Binding DataManagerVM.ChampionVMs}" SelectionMode="Single" RowHeight="75">
<ListView.Behaviors>
<toolkit:EventToCommandBehavior EventName="ItemTapped"
Command="{Binding ItemTappedCommand}"
EventArgsConverter="{StaticResource ItemTappedEventArgsConverter}"/>
</ListView.Behaviors>
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell Height="75">

@ -9,14 +9,8 @@ public partial class ChampionListPage : ContentPage
public ChampionListPage(DataManagerVM dataManager)
{
VMApp = new ChampionListPageVM(dataManager);
VMApp = new ChampionListPageVM(dataManager, Navigation);
InitializeComponent();
BindingContext = VMApp;
}
async void ListView_ItemTapped(System.Object sender, Microsoft.Maui.Controls.ItemTappedEventArgs e)
{
await Navigation.PushAsync(new ChampionDetail((sender as ListView).SelectedItem as ChampionVM));
(sender as ListView).SelectedItem = null;
}
}
Loading…
Cancel
Save