Prism Library Quick Tip – Snippets

Prism Library Quick Tip – Snippets

The Prism Template pack, available on Visual Studio Marketplace, offers a collection of helpful snippets to speed up your development. To use the snippets in Visual Studio, simply type the shortcut (e.g. propp) and press TAB.

Here is a quick list of each as a handy reference:

propp

Generate a property with a backing field, that depends on BindableBase. This means it will generate a standard property, but with a setter that uses the BindableBase SetProperty method, e.g.

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

cmd

Generates a DelegateCommand property, with backing field and the associated Execute method, e.g.

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

void ExecuteCommandName()
{

}

cmdfull

Generate a DelegateCommand property, with backing field as well as its associated Execute method. It also creates the CanExecute method for you, e.g.

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

void ExecuteCommandName()
{

}

bool CanExecuteCommandName()
{
    return true;
}

cmdg

Similar to the cmd snippet mentioned above, but this one generates a generic DelegateCommand property

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

void ExecuteCommandName(string parameter)
{

}

cmdgfull

Similar to the cmdfull snippet mentioned above, but this one generates a generic DelegateCommand property with its associated 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;
}

These snippets are incredibly handy when working with Prism as it really makes it easy to add the code elements essential for the framework to work smoothly.

To read more about the Prism Library, visit [prismlibrary.com/](http://prismlibrary.com "prismlibrary.com")

Thank you for reading. Until next time, keep coding!