I want to pass the Id of the viewmodel as a commandparameter using a popup

Ronald Rex 1,666 Reputation points
2023-05-31T13:45:32.6766667+00:00

Hi Friends,

I want to pass the Id of the viewmodel class as a commandparameter using a popup. Thanks !


View Model


[RelayCommand]
	async Task UpdateUdf()
	{
    
    }

	

XAML


<toolkit:Popup   
  xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
  xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
  xmlns:sf ="clrnamespace:Syncfusion.Maui.Core;assembly=Syncfusion.Maui.Core"
  xmlns:toolkit="http://schemas.microsoft.com/dotnet/2022/maui/toolkit"
  x:Class="DesktopUserInterface.Views.EditUserDefinedFieldPopupView"
                 xmlns:local="clr-namespace:DesktopUserInterface.ViewModel"
                 x:DataType="local:PayerEditViewModel"
                 CanBeDismissedByTappingOutsideOfPopup="False"
                 VerticalOptions="Fill">
 
 
                      
                       
<Button   Text= "OK"   Command="{Binding UpdateUdfCommand}" />
                     
</toolkit:Popup>


.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
4,150 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
11,557 questions
0 comments No comments
{count} votes

Accepted answer
  1. Wenyan Zhang (Shanghai Wicresoft Co,.Ltd.) 36,431 Reputation points Microsoft External Staff
    2023-06-01T07:59:02.0733333+00:00

    Hello,

    You are using [RelayCommand], it's a third-party tool feature and not supported on Q&A. Please see Commanding - .NET MAUI | Microsoft Learn.

    I want to pass the Id of the viewmodel class as a commandparameter using a popup.

    You can refer to the following code:

    ViewModel (Adding ID property of the viewmodel class)

    public class PayerEditViewModel
    {
        public string ID { get; set; }// ID property
        public ICommand UpdateUdfCommand { private set; get; }
        public PayerEditViewModel()
        {
            UpdateUdfCommand = new Command<String>(UpdateUdf);
        }
        private void UpdateUdf(String ID)
        {// commandparameter
    
        }
    
    }
    

    XAML of EditUserDefinedFieldPopupView

      <VerticalStackLayout>
            <Button  Text= "OK"  Command="{Binding UpdateUdfCommand}" CommandParameter="{Binding ID}" />
        </VerticalStackLayout>
    

    Code Behind

    public EditUserDefinedFieldPopupView(PayerEditViewModel vm)
        {
            InitializeComponent();
            this.BindingContext = vm;
        }
    

    Presenting this Popup in MainPage

    private void OnCounterClicked(object sender, EventArgs e)
        {
            var ViewModel = new PayerEditViewModel();
            ViewModel.ID = "111";
            var popup = new EditUserDefinedFieldPopupView(ViewModel);
            this.ShowPopup(popup);// then you could click the "OK" button to check if "111" has been passed
        }
    

    Best Regards,

    Wenyan Zhang


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

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.