Finalized Maui-series for vs development

This commit is contained in:
2025-08-21 22:08:06 +02:00
parent 543b9c2aaf
commit 8b7afd50a4
10 changed files with 95 additions and 13 deletions

View File

@ -8,6 +8,7 @@
// Register routes for navigation // Register routes for navigation
Routing.RegisterRoute(nameof(Views.UserDetailView), typeof(Views.UserDetailView)); Routing.RegisterRoute(nameof(Views.UserDetailView), typeof(Views.UserDetailView));
Routing.RegisterRoute(nameof(Views.ProductDetailView), typeof(Views.ProductDetailView));
} }
} }

View File

@ -1,6 +1,7 @@
using AdventureWorks.EntityLayer; using AdventureWorks.EntityLayer;
using AdventureWorks.ViewModelLayer.ViewModelClasses; using AdventureWorks.ViewModelLayer.ViewModelClasses;
using Common.Library; using Common.Library;
using System.Windows.Input;
namespace AdventureWorks.MAUI.CommandClasses namespace AdventureWorks.MAUI.CommandClasses
{ {
@ -14,6 +15,44 @@ namespace AdventureWorks.MAUI.CommandClasses
{ {
} }
#endregion #endregion
public ICommand SaveCommand { get; private set; }
public ICommand EditCommand { get; private set; }
private bool _IsSaveCommandEnabled = true;
public bool IsSaveCommandEnabled
{
get { return _IsSaveCommandEnabled; }
set
{
_IsSaveCommandEnabled = value;
RaisePropertyChanged(nameof(IsSaveCommandEnabled));
}
}
public override void Init()
{
base.Init();
SaveCommand = new Command(async () => await SaveAsync(), () => IsSaveCommandEnabled);
EditCommand = new Command<int>(async (id) => await EditAsync(id), (id) => id > 0);
}
public async Task<bool> SaveAsync()
{
var ret = base.Save();
if (ret)
{
await Shell.Current.GoToAsync("..");
}
return ret;
}
protected async Task EditAsync(int id)
{
await Shell.Current.GoToAsync($"{nameof(Views.ProductDetailView)}?id={id}");
}
public void LoadProducts() public void LoadProducts()
{ {
Get(); Get();

View File

@ -38,16 +38,34 @@ public class UserViewModelCommands : UserViewModel
#region Commands #region Commands
public ICommand SaveCommand { get; private set; } public ICommand SaveCommand { get; private set; }
public ICommand EditCommand { get; private set; }
#endregion #endregion
#region Init Method #region Init Method
public override void Init() public override void Init()
{ {
base.Init(); base.Init();
SaveCommand = new Command(() => Save(), () => IsSaveCommandEnabled); SaveCommand = new Command(async () => SaveAsync(), () => IsSaveCommandEnabled);
EditCommand = new Command<int>(async (id) => await EditAsync(id), (id) => id > 0);
} }
#endregion #endregion
protected async Task EditAsync(int id)
{
await Shell.Current.GoToAsync($"{nameof(Views.UserDetailView)}?id={id}");
}
public async Task<bool> SaveAsync()
{
var ret = base.Save();
if (ret)
{
await Shell.Current.GoToAsync("..");
}
return ret;
}
} }

View File

@ -1,8 +1,10 @@
<?xml version="1.0" encoding="utf-8" ?> <?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui" <ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:partial="clr-namespace:AdventureWorks.MAUI.ViewsPartial"
xmlns:vm="clr-namespace:AdventureWorks.MAUI.CommandClasses"
x:Class="AdventureWorks.MAUI.Views.ProductDetailView" x:Class="AdventureWorks.MAUI.Views.ProductDetailView"
xmlns:partial="clr-namespace:AdventureWorks.MAUI.ViewsPartial" x:DataType="vm:ProductViewModelCommands"
Title="Product Information"> Title="Product Information">
<Border Style="{StaticResource Border.Page}"> <Border Style="{StaticResource Border.Page}">

View File

@ -1,9 +1,24 @@
using AdventureWorks.MAUI.CommandClasses;
namespace AdventureWorks.MAUI.Views; namespace AdventureWorks.MAUI.Views;
[QueryProperty(nameof(ProductId), "id")]
public partial class ProductDetailView : ContentPage public partial class ProductDetailView : ContentPage
{ {
public ProductDetailView() public ProductDetailView(ProductViewModelCommands viewModel)
{ {
InitializeComponent(); InitializeComponent();
} ViewModel = viewModel;
}
public ProductViewModelCommands ViewModel { get; set; }
public int ProductId { get; set; }
protected override void OnAppearing()
{
base.OnAppearing();
BindingContext = ViewModel;
//ViewModel.GetProductCategories();
//ViewModel.GetProductModels();
ViewModel.Get(ProductId);
}
} }

View File

@ -6,6 +6,7 @@
xmlns:vm="clr-namespace:AdventureWorks.MAUI.CommandClasses" xmlns:vm="clr-namespace:AdventureWorks.MAUI.CommandClasses"
xmlns:model="clr-namespace:AdventureWorks.EntityLayer;assembly=AdventureWorks.EntityLayer" xmlns:model="clr-namespace:AdventureWorks.EntityLayer;assembly=AdventureWorks.EntityLayer"
x:DataType="vm:ProductViewModelCommands" x:DataType="vm:ProductViewModelCommands"
x:Name="ProductListPage"
Title="ProductListView"> Title="ProductListView">
<Border Style="{StaticResource Screen.Border}"> <Border Style="{StaticResource Screen.Border}">
<Grid> <Grid>
@ -36,7 +37,9 @@
<Label Text="{Binding ListPrice, StringFormat='{0:C}'}" /> <Label Text="{Binding ListPrice, StringFormat='{0:C}'}" />
</HorizontalStackLayout> </HorizontalStackLayout>
<HorizontalStackLayout> <HorizontalStackLayout>
<Button Text="Edit" /> <Button Text="Edit"
CommandParameter="{Binding ProductID}"
Command="{Binding Source={x:Reference ProductListPage}, Path=BindingContext.EditCommand}"/>
<Button Text="Delete" /> <Button Text="Delete" />
</HorizontalStackLayout> </HorizontalStackLayout>
</VerticalStackLayout> </VerticalStackLayout>

View File

@ -1,7 +1,7 @@
using AdventureWorks.MAUI.CommandClasses; using AdventureWorks.MAUI.CommandClasses;
namespace AdventureWorks.MAUI.Views; namespace AdventureWorks.MAUI.Views;
[QueryProperty(nameof(UserId), "id")]
public partial class UserDetailView : ContentPage public partial class UserDetailView : ContentPage
{ {
public UserDetailView(UserViewModelCommands viewModel) public UserDetailView(UserViewModelCommands viewModel)
@ -11,6 +11,7 @@ public partial class UserDetailView : ContentPage
} }
public UserViewModelCommands ViewModel { get; set; } public UserViewModelCommands ViewModel { get; set; }
public int UserId { get; set; }
protected override void OnAppearing() protected override void OnAppearing()
{ {
@ -20,7 +21,7 @@ public partial class UserDetailView : ContentPage
ViewModel.GetPhoneTypes(); ViewModel.GetPhoneTypes();
ViewModel.Get(1); // Assuming you want to get the user with ID 1 ViewModel.Get(UserId);
} }
} }

View File

@ -6,7 +6,7 @@
xmlns:model="clr-namespace:AdventureWorks.EntityLayer;assembly=AdventureWorks.EntityLayer" xmlns:model="clr-namespace:AdventureWorks.EntityLayer;assembly=AdventureWorks.EntityLayer"
x:Class="AdventureWorks.MAUI.Views.UserListView" x:Class="AdventureWorks.MAUI.Views.UserListView"
x:DataType="vm:UserViewModelCommands" x:DataType="vm:UserViewModelCommands"
x:Name="UserListPage"
Title="User List"> Title="User List">
<Border Style="{StaticResource Screen.Border}"> <Border Style="{StaticResource Screen.Border}">
@ -35,7 +35,9 @@
<Label Text="{Binding Email}" /> <Label Text="{Binding Email}" />
</HorizontalStackLayout> </HorizontalStackLayout>
<HorizontalStackLayout> <HorizontalStackLayout>
<Button Text="Edit" /> <Button Text="Edit"
CommandParameter="{Binding UserId}"
Command="{Binding Source={x:Reference UserListPage}, Path=BindingContext.EditCommand}" />
<Button Text="Delete" /> <Button Text="Delete" />
</HorizontalStackLayout> </HorizontalStackLayout>
</VerticalStackLayout> </VerticalStackLayout>

View File

@ -85,7 +85,8 @@ public class ProductViewModel : ViewModelBase
public bool Save() public bool Save()
{ {
throw new NotImplementedException("Save method is not implemented yet."); // TODO: Implement Save logic
return true;
} }
} }

View File

@ -138,7 +138,7 @@ public class UserViewModel : ViewModelBase
#region Save Method #region Save Method
public virtual bool Save() public virtual bool Save()
{ {
System.Diagnostics.Debugger.Break(); // System.Diagnostics.Debugger.Break();
return true; return true;
} }
#endregion #endregion