C# Prism Template Pack Code Snippets (Visual Studio Code)
Visual Studio Code snippets for C# Prism Template Pack.
Registering Custom Code Snippets in Visual Studio Code
You can create code snippet files using the following steps:
-
Select File > Preferences > User Snippets from the code editor's top menu.
-
Snippets are written in JSON format.
Code Snippets
propp
Defines a property that requires update notifications.
"Create Bindable Property": {
"scope": "csharp",
"prefix": "propp",
"body": [
"private ${1:Type} _${3:${2/(.*)/${1:/camelcase}/}};",
"public ${1:Type} ${2:Name}",
"{",
" get { return _$3; }",
" set { SetProperty(ref _$3, value); }",
,
"}"
],
"description": "Create a property, with a backing field, that depends on BindableBase."
}
About ${3:...}
${2/(.*)/${1:/camelcase}/}: This part is a combination of regular expression and replacement pattern. It generates the name of the backing field based on the value of${2:Name}.(.*): This is a regular expression capture group. It captures the property name (Name) entered by the user.${1:/camelcase}: This is a replacement pattern for converting the captured string to camel case.${1:...}references the captured value, and:camelcaseinstructs camel case conversion.
cmd
Delegate command.
"Create DelegateCommand Property": {
"scope": "csharp",
"prefix": "cmd",
"body": [
"public DelegateCommand ${1:Command} => new DelegateCommand(() =>",
"{",
"",
"});"
],
"description": "Create a DelegateCommand property with a private setter."
}
cmdg
Parameterized delegate command.
"Create Generic DelegateCommand Property": {
"scope": "csharp",
"prefix": "cmdg",
"body": [
"public DelegateCommand<${2:Param}> ${1:Command} => new DelegateCommand<${2:Param}>((p) =>",
"{",
"",
"});"
],
"description": "Create a generic DelegateCommand property."
}
Related plants
More Tech articles →C# | How to call a MainWindow method from a partial View in WPF Prism
In WPF Prism, you can call a method on the Main Window from a partial view. Using Prism's Event Aggregator avoids direct references between view models and makes it easy to handle events raised within the application.
#csharp#wpf#prismC# | How to call a View method in ContentRegion from MainWindow in WPF Prism
In WPF Prism, an application may consist of a main window and a set of regions contained within it, hosting views and view models that communicate with each other. This explains how to call a method on a view or view model in the Content Region from the Main Window.
#csharp#wpf#prismC# | How to implement video (MediaElement) in WPF Prism using the MVVM pattern
How to implement video playback (MediaElement.Play()) in WPF Prism using the MVVM pattern.
#csharp#wpf#prism