Command does not hit

Eduardo Gomez 3,631 Reputation points
2025-05-08T21:29:08.7766667+00:00

I have this chunk of code

   <sfPopup:SfPopup
       x:Name="UserProfilePopup"
       AbsoluteY="20"
       AcceptButtonText="Save and close"
       AcceptCommand="{Binding SavePopUpContentCommand}"
       HeaderHeight="90"
       HeightRequest="400"
       RelativePosition="AlignTopRight"
       RelativeView="{x:Reference UserProfileImage}"
       ShowFooter="True"
       ShowHeader="True"
       ShowOverlayAlways="False"
       WidthRequest="400">
       <sfPopup:SfPopup.HeaderTemplate>
           <DataTemplate x:DataType="model:LocalUser">
               <toolkit:AvatarView
                   Margin="20,10,0,0"
                   BorderColor="Black"
                   BorderWidth="1"
                   CornerRadius="80"
                   FontFamily="MaterialSymbol"
                   FontSize="20"
                   HeightRequest="80"
                   HorizontalOptions="Start"
                   ImageSource="{Binding ImagePath}"
                   Text="{Static icons:MateriallFontGlyphs.Add_a_photo}"
                   TextColor="Black"
                   WidthRequest="80">
                   <toolkit:AvatarView.GestureRecognizers>
                       <PointerGestureRecognizer
                           x:Name="AvatarImage"
                           x:DataType="vm:AppShellViewModel"
                           PointerEntered="AvatarImage_PointerEntered"
                           PointerExited="AvatarImage_PointerExited" />
                   </toolkit:AvatarView.GestureRecognizers>
                   <toolkit:AvatarView.Behaviors>
                       <toolkit:EventToCommandBehavior
                           x:DataType="vm:AppShellViewModel"
                           Command="{Binding AvatarImageClickedCommand}" />
                   </toolkit:AvatarView.Behaviors>
               </toolkit:AvatarView>
           </DataTemplate>
       </sfPopup:SfPopup.HeaderTemplate>
       <sfPopup:SfPopup.PopupStyle>
           <sfPopup:PopupStyle CornerRadius="0" />
       </sfPopup:SfPopup.PopupStyle>
       <sfPopup:SfPopup.ContentTemplate>
           <DataTemplate x:DataType="model:LocalUser">
               <Grid
                   Padding="20"
                   HorizontalOptions="Center"
                   RowDefinitions="80,80"
                   RowSpacing="5"
                   VerticalOptions="Center">
                   <controls:MaterialEntry
                       Hint="Name"
                       HintColor="Black"
                       HorizontalOptions="Start"
                       ShowIcon="False"
                       Text="{Binding Username}"
                       TextColor="Black" />
                   <controls:MaterialEntry
                       Grid.Row="1"
                       Hint="Status"
                       HintColor="Black"
                       HorizontalOptions="Start"
                       ShowIcon="False"
                       Text="{Binding StatusMessage}"
                       TextColor="Black" />
               </Grid>
           </DataTemplate>
       </sfPopup:SfPopup.ContentTemplate>


I made my viewModel

namespace FireChat.ViewModels;

public partial class AppShellViewModel : BaseViewModel {

    readonly FirebaseAuthClient _authClient;
    readonly WeakReferenceMessenger _messenger;
    readonly IMediaPicker _mediaPicker;

    [ObservableProperty]
    LocalUser localUser = new();

    [ObservableProperty]
    string? _userName;

    public AppShellViewModel(FirebaseAuthClient authClient, WeakReferenceMessenger messenger, IMediaPicker mediaPicker) {

        _authClient = authClient;

        if(_authClient.User != null) {
            _userName = _authClient.User.Info.DisplayName;
        }

        _messenger = messenger;
        _mediaPicker = mediaPicker;
    }

    [RelayCommand]
    async Task SignOut() {

        _authClient.SignOut();

        await Shell.Current.GoToAsync("..");
    }

    [RelayCommand]
    void OpenProfile() {

        _messenger.Send("OpenProfile");

    }

    [RelayCommand]
    void SavePopUpContent() {

        _messenger.Send("SavePopUpContent");
    }

    [RelayCommand]
    async Task AvatarImageClicked() {

        await Shell.Current.DisplayActionSheet("Choose an option", "Cancel", null, "Take a photo", "Choose from gallery");
        var result = await _mediaPicker.PickPhotoAsync(new MediaPickerOptions {
            Title = "Pick a photo"
        });
        if(result != null) {
            var stream = await result.OpenReadAsync();
            LocalUser.ImagePath = stream.ToString();
        }
    }
}

and it does not want to hit the command, to show me the propt

code

https://github.com/eduardoagr/MauiSamples

.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
4,102 questions
0 comments No comments
{count} votes

Accepted answer
  1. Michael Taylor 58,866 Reputation points
    2025-05-08T22:08:18.6666667+00:00

    Can you provide more detail and steps to replicate the issue? It doesn't appear that the code you showed is actually displayed at startup and the login screen doesn't do anything related to this.

    Just on a cursory glance, the binding that you are using references -Command but the view model doesn't name them as -Command. To me it looks like you need to adjust the view model property names to match what you're using for the binding (e.g. AvatarImageClickedCommand).


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.