Код XAML
Код: Выделить всё
Код: Выделить всё
using CommunityToolkit.Maui.Views;
using LockAndKeyMaui.ViewModels;
namespace LockAndKeyMaui;
public partial class MsgBox : Popup
{
public MsgBox(MsgViewModel msgVwMod)
{
InitializeComponent();
BindingContext = msgVwMod;
}
}
Код: Выделить всё
using CommunityToolkit.Maui.Core;
using CommunityToolkit.Mvvm.ComponentModel;
using System.ComponentModel;
namespace LockAndKeyMaui.ViewModels
{
public class MsgViewModel : ObservableObject, INotifyPropertyChanged
{
private string msgtxt, hdrtxt;
readonly IPopupService popupService;
public MsgViewModel(IPopupService popupService)
{
this.popupService = popupService;
}
public string MsgTxt
{
get => msgtxt;
set
{
this.msgtxt = value;
OnPropChg(nameof(MsgTxt));
}
}
public string HdrTxt
{
get => hdrtxt;
set
{
hdrtxt = value;
OnPropChg(nameof(HdrTxt));
}
}
public event PropertyChangedEventHandler? PropertyChanged;
private void OnPropChg(string prName)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(prName));
}
}
}
Код: Выделить всё
namespace LockAndKeyMaui.ViewModels
{
public partial class MainViewModel : INotifyPropertyChanged
{
public IPopupService popupService;
public MainViewModel(IPopupService popServ)
{
Laks = new LakFuncs();
popupService = popServ;
}
[RelayCommand]
public static async Task CopyUsr(object sender)
{
var dataView = sender as SfDataGrid;
PswdWthGrp row = (PswdWthGrp)dataView!.SelectedRow;
if (row != null)
{
await Clipboard.SetTextAsync(row.UsrName);
popupService.ShowPopupAsync(onPresenting: vwMod => vwMod.PerformUpdts("User Name copied.", ""));
await Task.Delay(1500);
popupService.ClosePopup();
return;
}
}
}
}
Мне также хотелось бы иметь возможность передавать в это всплывающее окно несколько переменных.
Итак, как мне заставить все это работать?
Подробнее здесь: https://stackoverflow.com/questions/793 ... view-model