prism8 for wpf study notes

Posted by patheticsam on Sat, 15 Jan 2022 00:17:51 +0100

What is Prism?

Prism is a framework for building loosely coupled, maintainable, and testable XAML applications in WPF and Xamarin Forms. Prism provides the implementation of a set of design patterns. These patterns help to write well structured and maintainable XAML applications, including MVVM, dependency injection, command, EventAggregator, etc., which are suitable for the development of large projects in WPF.

Download and install Prism

system requirements

  • . NET Framework 4.5 or later
  • Visual Studio 2017 or later

Source code and examples

Prism source code and documentation

WPF-Sample

NuGet packages Install prism

There are several core packages, prism Core, Prism.Wpf,Prism.Unity,Prism.DryIoc

Main program from prism Unity or prism Dryioc can be installed by selecting one.

Choose prism here Unity
Enter in the package management console

Install-Package Prism.Unity -Version 8.1.97

Install the productivity tool (you can go back and install it after knowing the basic composition of prism)

prism provides some project modules and code snippets that are easy to develop

Prism Template Pack

To install in Visual Studio 2019, simply go to * * Visual Studio - > extensions - > manageextensions - > Online - > visual studio marketplace * * and search the online gallery for "Prism Template Pack":

Managing installation in Visual Studio extensions

Snippets (code snippets)

After entering the following keywords in VS, press Tab 2 times to automatically generate the following code:

propp has properties that support fields, depending on BindableBase

private string _fieldName;
public string PropertyName
{
    get { return _fieldName; }
    set { SetProperty(ref _fieldName, value); }
}

cmd creates a generic DelegateCommand

After entering cmd, press Tab 2 times to automatically generate the following code:

private DelegateCommand _fieldName;
public DelegateCommand CommandName =>
    _fieldName ?? (_fieldName = new DelegateCommand(ExecuteCommandName));

void ExecuteCommandName()
{

}

cmdfull - create the DelegateCommand property using the Execute and CanExecute methods

private DelegateCommand _fieldName;
public DelegateCommand CommandName =>
    _fieldName ?? (_fieldName = new DelegateCommand(ExecuteCommandName, CanExecuteCommandName));

void ExecuteCommandName()
{

}

bool CanExecuteCommandName()
{
    return true;
}

cmdg - create a generic DelegateCommand

    private DelegateCommand<string> _fieldName;
    public DelegateCommand<string> CommandName =>
        _fieldName ?? (_fieldName = new DelegateCommand<string>(ExecuteCommandName));

void ExecuteCommandName(string parameter)
{

}

cmdgfull - create a generic DelegateCommand with properties of Execute and CanExecute methods

private DelegateCommand<string> _fieldName;
public DelegateCommand<string> CommandName =>
    _fieldName ?? (_fieldName = new DelegateCommand<string>(ExecuteCommandName, CanExecuteCommandName));

void ExecuteCommandName(string parameter)
{

}

bool CanExecuteCommandName(string parameter)
{
    return true;
}

Project template

  • Prism Blank App - this is a project template that essentially creates a new WPF shell
    Application. It will have a basic boot program that initializes the application and displays the shell. It will have a MainWindow and a
    The MainWindowViewModel is located in the Views and ViewModels folders, respectively.
  • Prism Module - this project template will add a new project to your solution that will act as a Prism Module. It defines a class that implements IModule, which contains two empty folders for your view and view model.

Postscript

Personal blog website https://onebyone.icu/

Technical exchange Q group: 1012481075. There are various popular books and materials in the group

The article will be updated in the official account, WeChat search OneByOneDotNet can be concerned.

Your encouragement is my great motivation. Praise is free. Thank you for your feedback. Just like comments.

Topics: C# .NET WPF prism