command et vm app

master
Mathis RIBEMONT 2 years ago
parent ba405704e8
commit 27a9e85563

@ -57,6 +57,7 @@
<ItemGroup>
<Folder Include="Views\Components\" />
<Folder Include="VMApp\" />
</ItemGroup>
<ItemGroup>
@ -76,9 +77,11 @@
<ItemGroup>
<None Remove="Converters\" />
<None Remove="VMApp\" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\VM\VM.csproj" />
<ProjectReference Include="..\StubLib\StubLib.csproj" />
<ProjectReference Include="..\LolToolkit\LolToolkit.csproj" />
</ItemGroup>
</Project>

@ -0,0 +1,45 @@
using System;
using System.ComponentModel;
using System.Windows.Input;
using VM;
using LolToolkit;
namespace ClientMAUI.VMApp
{
public class ChampionEditPageVM : PropertyChangedSender
{
public ChampionVM ChampionVM { get; set; }
public ICommand AddSkillCommand { get; private set; }
public string SkillName {
get => _skillName;
set
{
if(value != _skillName)
{
_skillName = value;
OnPropertyChanged();
(AddSkillCommand as Command).ChangeCanExecute();
}
}
}
private string _skillName = "";
public ChampionEditPageVM(ChampionVM championVM)
{
this.ChampionVM = championVM;
AddSkillCommand = new Command(
canExecute: () =>
{
return this.SkillName.Trim() != "" && this.SkillName != null;
},
execute: () =>
{
ChampionVM.AddSkill(SkillName);
SkillName = "";
});
}
}
}

@ -23,7 +23,7 @@
<Label Text="{Binding Bio}"/>
<Label Text="Caractéristiques" Style="{StaticResource h3}" Padding="0,10,0,0"/>
<CollectionView ItemsSource="{Binding Characteristics}">
<CollectionView ItemsSource="{Binding Characteristics}" VerticalScrollBarVisibility="Never">
<CollectionView.ItemsLayout>
<GridItemsLayout Orientation="Vertical" Span="3"
HorizontalItemSpacing="10"

@ -11,32 +11,30 @@
RowSpacing="5">
<Label Text="Name" Grid.Row="0" Grid.Column="0" VerticalTextAlignment="Center"/>
<Entry Text="{Binding Name}" Grid.Row="0" Grid.Column="1"/>
<Entry Text="{Binding ChampionVM.Name}" Grid.Row="0" Grid.Column="1"/>
<Label Text="Bio" Grid.Row="1" Grid.Column="0" VerticalTextAlignment="Center"/>
<Editor Text="{Binding Bio}" Grid.Row="1" Grid.Column="1"/>
<Editor Text="{Binding ChampionVM.Bio}" Grid.Row="1" Grid.Column="1"/>
<Label Text="Class" Grid.Row="2" Grid.Column="0" VerticalTextAlignment="Center"/>
<Editor Text="Classe" Grid.Row="2" Grid.Column="1"/>
<Label Text="Compétences" Grid.Row="3" Grid.Column="0" VerticalTextAlignment="Center"/>
<VerticalStackLayout Grid.Row="3" Grid.Column="1">
<CollectionView SelectionMode="None" ItemsSource="{Binding Skills}">
<CollectionView SelectionMode="None" ItemsSource="{Binding ChampionVM.Skills}" VerticalScrollBarVisibility="Never">
<CollectionView.ItemTemplate>
<DataTemplate>
<Border StrokeThickness="1">
<VerticalStackLayout>
<Label Text="{Binding Name}"/>
<Entry Text="{Binding Description}"/>
</VerticalStackLayout>
</Border>
<VerticalStackLayout>
<Label Text="{Binding Name}"/>
<Entry Text="{Binding Description}"/>
</VerticalStackLayout>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
<Grid ColumnDefinitions="*,Auto">
<Entry Placeholder="Nom de compétence" x:Name="SkillName"/>
<Button Text="+" Grid.Column="1" Command="{Binding AddSkillCommand}" CommandParameter="Test"/>
<Entry Placeholder="Nom de compétence" Text="{Binding SkillName}"/>
<Button Text="+" Grid.Column="1" Command="{Binding AddSkillCommand}"/>
</Grid>
</VerticalStackLayout>
</Grid>

@ -1,15 +1,18 @@
using VM;
using ClientMAUI.VMApp;
namespace ClientMAUI.Views.Pages;
public partial class ChampionEditPage : ContentPage
{
public ChampionVM Champion;
public ChampionVM ChampionVM;
public ChampionEditPageVM ChampionEditPageVM;
public ChampionEditPage(ChampionVM champion)
{
this.Champion = champion;
this.ChampionEditPageVM = new ChampionEditPageVM(champion);
this.ChampionVM = champion;
InitializeComponent();
BindingContext = this.Champion;
BindingContext = this.ChampionEditPageVM;
}
}

@ -1,5 +1,4 @@
using System;
using Microsoft.Maui.Controls;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Runtime.CompilerServices;
@ -81,20 +80,6 @@ namespace VM
get => Model.Class.ToString();
}
public bool IsEditing
{
get => _isEditing;
private set
{
if (value != _isEditing)
{
_isEditing = value;
OnPropertyChanged();
}
}
}
private bool _isEditing;
public ChampionVM(Champion model)
{
_model = model;
@ -102,18 +87,6 @@ namespace VM
{
_skillVMs.Add(new SkillVM(s));
}
AddSkillCommand = new Command<string>(
canExecute: (string name) =>
{
return !IsEditing && name.Trim() != "";
},
execute: (string name) =>
{
IsEditing = true;
AddSkill(name);
IsEditing = false;
});
}
public void AddSkill(string name)

Loading…
Cancel
Save