Created
October 28, 2023 18:06
-
-
Save androidmads/354012432f9ac014551d5cb774c48e3b to your computer and use it in GitHub Desktop.
.NET MAUI - MVVM with MVVM toolkit sample
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8" ?> | |
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui" | |
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" | |
x:Class="MauiMVVM.Views.ItemEntryPage" | |
Title="Item Entry"> | |
<StackLayout Margin="20" | |
Spacing="10"> | |
<VerticalStackLayout> | |
<Label Text="Name:" | |
FontSize="16"/> | |
<Entry Text="{Binding Name}" | |
Placeholder="Item Name"/> | |
</VerticalStackLayout> | |
<VerticalStackLayout> | |
<Label Text="Description:" | |
FontSize="16"/> | |
<Entry Text="{Binding Description}" | |
Placeholder="Item Description"/> | |
</VerticalStackLayout> | |
<Button x:Name="btn_save" | |
Text="Save" | |
Command="{Binding SaveCommand}"/> | |
</StackLayout> | |
</ContentPage> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using MauiMVVM.ViewModels; | |
namespace MauiMVVM.Views; | |
public partial class ItemEntryPage : ContentPage | |
{ | |
public ItemEntryPage() | |
{ | |
InitializeComponent(); | |
BindingContext = new ItemEntryPageModel(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Microsoft.Toolkit.Mvvm.ComponentModel; | |
using Microsoft.Toolkit.Mvvm.Input; | |
namespace MauiMVVM.ViewModels; | |
public partial class ItemEntryPageModel : ObservableObject | |
{ | |
[ObservableProperty] | |
private int _id; | |
[ObservableProperty] | |
private string _name; | |
[ObservableProperty] | |
private string _description; | |
[ICommand] | |
public async void Save() | |
{ | |
await Application.Current.MainPage.DisplayAlert("MAUI MVVM Sample", "Item Saved Successfully", "OK"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment