You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

Mvvm.CommonInteractions.Uno

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

Mvvm.CommonInteractions.Uno

Common MVVM Level Interactions(like open/save file) for WPF/UWP/WinUI/Uno/Avalonia platforms ⭐ Last 10 features: - feat: Updated to net8.0. 2023-12-18 - feat: Updated packages. 2023-08-19 - feat: Updated NuGet packages. 2023-02-27 - feat: Added MAUI partial support. 2023-02-27 - feat: Added net7 targets. 2023-01-06 - feat: Updated NuGet packages. 2023-01-06 - feat: Added HostBuilder extensions. 2023-01-06 - feat: Removed ReactiveUI dependency. 2022-08-22 - feat: To IsExternalInit package. 2022-08-22 - feat: Updated NuGet packages. 2022-08-11 🐞 Last 10 bug fixes: - fix: Fixed WebAssembly app. 2023-01-07 - fix: Fixed Uno projects. 2023-01-07 - fix: Fixed Avalonia dependencies. 2023-01-06 - fix: Fixed GetRequiredWindow exception message. 2022-08-22 - fix: To WinRT.Interop. 2022-07-14 - fix: Disabled linker. 2022-07-01 - fix: Fixed Uno targets. 2022-03-18 - fix: Fixed missing Warning ContentDialog. 2022-03-17 - fix(apps): Fixed Uno.WinUI webassembly app. 2022-01-19 - fix: Fixed package description. 2021-12-22

1.0.68
nugetNuGet
Version published
Maintainers
1
Created
Source

Mvvm.CommonInteractions

Common MVVM Level Interactions(like open/save file) for WPF/UWP/WinUI/Uno/Avalonia/Maui platforms. Features:

  • Easy interactions with files, message boxes, web from MVVM level.
  • Enables drag-and-drop support at the ViewModel level.
  • Wide choice of platforms
  • Dependency injection friendly

NuGet

NuGet NuGet NuGet NuGet NuGet NuGet NuGet

Install-Package Mvvm.CommonInteractions.Core
Install-Package Mvvm.CommonInteractions.Wpf
Install-Package Mvvm.CommonInteractions.Uno
Install-Package Mvvm.CommonInteractions.Uwp
Install-Package Mvvm.CommonInteractions.WinUI
Install-Package Mvvm.CommonInteractions.Avalonia
Install-Package Mvvm.CommonInteractions.Maui

Usage

Add to your App constructors:


public sealed partial class App
{
    private IHost AppHost { get; }

    public App()
    {
        AppHost = Host
            .CreateDefaultBuilder()
            .ConfigureServices(static services =>
            {
                // Add all available interactions
                services.AddCommonInteractions();
                
                // or add only what you need
                services.AddSingleton<IFileInteractions, FileInteractions>();
                services.AddSingleton<IMessageInteractions, MessageInteractions>();
                services.AddSingleton<IWebInteractions, WebInteractions>();
            })
            .Build();

        // Optional. Displays unhandled exceptions using MessageInteractions.Exception.
        AppHost.Services.GetRequiredService<IMessageInteractions>().CatchUnhandledExceptions(this);

        // your code
    }
}

FileInteractions

// Open
var file = await FileInteractions.OpenFileAsync(new OpenFileArguments
{
    SuggestedFileName = "my.txt",
    Extensions = new[] { ".txt" },
    FilterName = "My txt files",
});
if (file == null)
{
    return;
}
var text = await file.ReadTextAsync().ConfigureAwait(true);

// Save (if you need to save file from previuos step)
await file.WriteTextAsync(text).ConfigureAwait(false);

// Save As
var file = await FileInteractions.SaveFileAsync(new SaveFileArguments(".txt")
{
    SuggestedFileName = "my.txt",
    FilterName = "My txt files",
});
if (file == null)
{
    return;
}
await file.WriteTextAsync(text).ConfigureAwait(false);

MessageInteractions

await MessageInteractions.ShowMessageAsync("Message");
await MessageInteractions.ShowWarningAsync("Warning");
await MessageInteractions.ShowExceptionAsync(new InvalidOperationException("Exception"));
bool question = await MessageInteractions.ShowQuestionAsync(new QuestionData("Are you sure?"));

WinUI requires a window to display the ContentDialog, so you'll need to set it explicitly in your App.OnLaunched:

protected override void OnLaunched(LaunchActivatedEventArgs args)
{
#if HAS_WINUI
    var window = new Window();
    MessageInteractions.Window = window;
#endif
}

WebInteractions

await WebInteractions.OpenUrlAsync("https://www.google.com/");

DragAndDropExtensions

// WPF
xmlns:dragAndDrop="clr-namespace:Mvvm.CommonInteractions;assembly=Mvvm.CommonInteractions.Wpf" 
// UWP/Uno
xmlns:dragAndDrop="using:Mvvm.CommonInteractions"
<Element
    AllowDrop="True"
    dragAndDrop:DragAndDropExtensions.DragFilesEnterCommand="{Binding DragFilesEnter}"
    dragAndDrop:DragAndDropExtensions.DragTextEnterCommand="{Binding DragTextEnter}"
    dragAndDrop:DragAndDropExtensions.DragLeaveCommand="{Binding DragLeave}"
    dragAndDrop:DragAndDropExtensions.DropFilesCommand="{Binding DropFiles}"
    dragAndDrop:DragAndDropExtensions.DropTextCommand="{Binding DropText}"
    >

Command arguments: DragFilesEnterCommand - FileData[] - Array of files.
DragTextEnterCommand - string - Text.
DragLeaveCommand - null.
DropFilesCommand - FileData[] - Array of files.
DropTextCommand - string - Text.

Contacts

Keywords

mvvm

FAQs

Package last updated on 18 Dec 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts