I’ve stripped almost everything, except the pertinent info. BaseViewModel inherits from ObservableObject. I started with a traditional WPF MVVM approach but could no longer make ICommands work. Although it does seem to work fine in a Maui Blazor Hybrid app but this is just a Maui app. From what I found RelayCommand is the correct approach with the latest Maui but my Button Command won’t work, no matter what I’ve tried. Any suggestions?
public partial class SignInViewModel : BaseViewModel
{
public RelayCommand UserLoginCommand { get; set; }
<code> public SignInViewModel()
{
UserLoginCommand = new RelayCommand(UserLogin);
}
async void UserLogin()
{
...
}
}
<?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"
xmlns:local="clr-namespace:NMMaui"
x:Class="NMMaui.Views.SignInPage"
xmlns:toolkit="http://schemas.microsoft.com/dotnet/2022/maui/toolkit"
xmlns:vm="clr-namespace:NMMaui.ViewModels"
Title="Sign In"
HeightRequest="600"
Background="Silver">
<ContentPage.BindingContext>
<vm:SignInViewModel/>
</ContentPage.BindingContext>
<VerticalStackLayout>
<Grid RowDefinitions="Auto,*">
<Button
Grid.Row="10"
Text="Sign In"
FontAttributes="Bold"
TextColor="White"
Margin="0,20"
HeightRequest="50"
CornerRadius="10"
HorizontalOptions="Center"
Command="{Binding UserLoginCommand}"
BackgroundColor="#508390"></Button>
</Grid>
</VerticalStackLayout>
</ContentPage>
</code>
<code> public SignInViewModel()
{
UserLoginCommand = new RelayCommand(UserLogin);
}
async void UserLogin()
{
...
}
}
<?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"
xmlns:local="clr-namespace:NMMaui"
x:Class="NMMaui.Views.SignInPage"
xmlns:toolkit="http://schemas.microsoft.com/dotnet/2022/maui/toolkit"
xmlns:vm="clr-namespace:NMMaui.ViewModels"
Title="Sign In"
HeightRequest="600"
Background="Silver">
<ContentPage.BindingContext>
<vm:SignInViewModel/>
</ContentPage.BindingContext>
<VerticalStackLayout>
<Grid RowDefinitions="Auto,*">
<Button
Grid.Row="10"
Text="Sign In"
FontAttributes="Bold"
TextColor="White"
Margin="0,20"
HeightRequest="50"
CornerRadius="10"
HorizontalOptions="Center"
Command="{Binding UserLoginCommand}"
BackgroundColor="#508390"></Button>
</Grid>
</VerticalStackLayout>
</ContentPage>
</code>
public SignInViewModel()
{
UserLoginCommand = new RelayCommand(UserLogin);
}
async void UserLogin()
{
...
}
}
<?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"
xmlns:local="clr-namespace:NMMaui"
x:Class="NMMaui.Views.SignInPage"
xmlns:toolkit="http://schemas.microsoft.com/dotnet/2022/maui/toolkit"
xmlns:vm="clr-namespace:NMMaui.ViewModels"
Title="Sign In"
HeightRequest="600"
Background="Silver">
<ContentPage.BindingContext>
<vm:SignInViewModel/>
</ContentPage.BindingContext>
<VerticalStackLayout>
<Grid RowDefinitions="Auto,*">
<Button
Grid.Row="10"
Text="Sign In"
FontAttributes="Bold"
TextColor="White"
Margin="0,20"
HeightRequest="50"
CornerRadius="10"
HorizontalOptions="Center"
Command="{Binding UserLoginCommand}"
BackgroundColor="#508390"></Button>
</Grid>
</VerticalStackLayout>
</ContentPage>