Notification texts go here Contact Us Buy Now!

How to close the MauiCommunityToolkit Popup from Viewmodel

PopupPage p = new PopupPage();
Application.Current.MainPage.ShowPopup(p);
await new TaskFactory().StartNew(() => { Thread.Sleep(5000); });
p.Close();

<Button
    Command="{Binding CloseClickCommand}"
    CommandParameter="{Binding Source={RelativeSource Mode=FindAncestor, AncestorType={x:Type mct:Popup}}}"
    Text="Close" />
public async Task CloseClickCommand(object obj)
{
    if (obj is Popup popup) 
    {
       popup.Close();
    }
}

<toolkit:Popup
    x:Class="VSTORE.Views.Popups.UserAdresPopupView"
    xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
    xmlns:toolkit="http://schemas.microsoft.com/dotnet/2022/maui/toolkit"
    xmlns:vm="clr-namespace:VSTORE.ViewModels.PopupsViewModel"
    x:Name="MYPOPUP"

  <Button
      Command="{Binding CloseCommand}"
      CommandParameter="{Binding Source={x:Reference MYPOPUP}}"
      Style="{StaticResource ConfirmButton}"
      Text="CLOSE" />
 [RelayCommand]
 public async Task Close(Popup popup)
 {
     popup.Close();
    await DisplayToast("Closed using button");
 }

Post a Comment

Cookie Consent
We serve cookies on this site to analyze traffic, remember your preferences, and optimize your experience.
Oops!
It seems there is something wrong with your internet connection. Please connect to the internet and start browsing again.
AdBlock Detected!
We have detected that you are using adblocking plugin in your browser.
The revenue we earn by the advertisements is used to manage this website, we request you to whitelist our website in your adblocking plugin.
Site is Blocked
Sorry! This site is not available in your country.