Microsoft.Extensions.DependencyInjection
ICommand
IDbConnection
CreateScope()
<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>
using System.Windows.Input; using CommunityToolkit.Mvvm.ComponentModel; namespace SamplePlugin.Configuration.MainPage; public partial class MainPageViewmodel : ObservableObject { public ICommand TestDialogServerCommand { get; set; } = null!; }
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... }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)