Click here to Skip to main content
16,023,224 members

Comments by rw-MassimoTamburini (Top 1 by date)

rw-MassimoTamburini 3-Nov-23 3:26am View    
Hi thanks for the answer.
What is a "task". What is the duration of "the" task? Sorry I was not so accurate. For task I meant the execution of a code inside the Command.
How does that relate to "stateless" and responsiveness? What do you mean by "stateless" and resposiveness?
Does it involve commits, rollbacks and retries? Inside the Command we could have them.
Is there a callback mechanism? Is it required or optional? What specifically are you referring to?

I can give you an example of our current setup of a page:

MainPageConfigurationUserControl.xaml
<UserControl x:Class="SamplePlugin.Configuration.MainPageConfigurationUserControl"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:mainPage="clr-namespace:SamplePlugin.Configuration.MainPage"
             mc:Ignorable="d"
             d:DesignHeight="600" d:DesignWidth="300" d:Background="White">
    <d:UserControl.DataContext>
        <mainPage:MainPageViewmodel/>
    </d:UserControl.DataContext>
    <Grid>
        <StackPanel >
            <Button x:Name="TestDialogButton" Command="{Binding TestDialogServerCommand}">Test dialog service</Button>
        </StackPanel>
        
    </Grid>
</UserControl>


MainPageViewModel.cs
using System.Windows.Input;
using CommunityToolkit.Mvvm.ComponentModel;

namespace SamplePlugin.Configuration.MainPage;

public partial class MainPageViewmodel : ObservableObject
{
    public ICommand TestDialogServerCommand { get; set; } = null!;
}


SamplePluginMainConfigurationPage.cs
using System.Data;
using System.Diagnostics;
using System.Windows.Controls;
using System.Windows.Media;
using Application;
using Application.Data;
using CommunityToolkit.Mvvm.Input;
using Microsoft.Extensions.DependencyInjection;
using SamplePlugin.Configuration;
using SamplePlugin.Configuration.MainPage;
using Serilog;

namespace SamplePlugin;

public class SamplePluginMainConfigurationPage
{
    // other code...

    private MainPageConfigurationUserControl userControl = null!;
    private readonly MainPageViewmodel viewmodel = new();
    private readonly IServiceProvider provider;

    public SamplePluginMainConfigurationPage(IServiceProvider provider)
    {
        this.provider = provider;
        // This could also be AsyncRelayCommand
        viewmodel.TestDialogServerCommand = new RelayCommand(ExecuteTestDialogServerCommand);
    }

    private void ExecuteTestDialogServerCommand()
    {
        var dialogService = provider.GetService<IDialogService>()!;
        dialogService.ShowMessageBox("Hello from SamplePluginMainConfigurationPage");
    }

    public UserControl GetUserControl()
    {
        return userControl;
    }
   
    // other code...
}