Skip to main content
rule official · GitHub

dotnet-wpf — GitHub Copilot rule: what it does, how to install

Directs GitHub Copilot to write WPF desktop code using the MVVM pattern on .NET 8.0+. It prevents business logic leaks into code-behind files.

Install into GitHub Copilot · Manually: put the files in place All methods and platforms ↓
.github/instructions/dotnet-wpf.instructions.md
Open on GitHub

What dotnet-wpf does

This instruction file configures GitHub Copilot for C# and WPF desktop projects. It automatically targets files matching **/*.xaml and **/*.cs. Copilot learns to separate UI markup from application logic using the Model-View-ViewModel structure, explicitly avoiding WinForms or UWP paradigms.

The rule steers generation toward CommunityToolkit.Mvvm or clean RelayCommand implementations. It enforces UI virtualization for heavy controls like ListView, non-blocking asynchronous calls via async/await, and strong typing with nameof instead of string-based bindings.

Projects running versions prior to .NET 8.0 will need adjustments because the provided snippets rely on modern C# source generators.

What it helps with

  • decouple XAML UI views from business logic via MVVM
  • scaffold ViewModels with INotifyPropertyChanged and RelayCommand
  • set up UI virtualization for ListView bound to an ObservableCollection
  • convert code-behind event handlers into testable ViewModel commands

Example prompts for the agent

  • Generate a ViewModel for a login screen with properties for username and password, and a LoginCommand
  • Write a XAML snippet for a ListView that uses UI virtualization and binds to an ObservableCollection
  • Refactor this code-behind click handler into a RelayCommand in the ViewModel

How to install dotnet-wpf

Manually: put the files in place

.github/instructions/dotnet-wpf.instructions.md

The applyTo field sets which files it applies to

Step by step, with commands for each platform: AGENTS.md vs CLAUDE.md: what they are and which one to use

Questions about dotnet-wpf

How to install dotnet-wpf in GitHub Copilot?

Place the rule file at .github/instructions/dotnet-wpf.instructions.md in your project repository. GitHub Copilot will apply these patterns whenever you work on *.xaml or *.cs files.

What does the dotnet-wpf rule do?

It enforces WPF best practices focused on MVVM architecture, clean data binding, and UI responsiveness. The prompt specifically instructs the model to omit business logic from code-behind files.

Which frameworks and libraries does dotnet-wpf prefer?

It targets .NET 8.0 or newer and prefers CommunityToolkit.Mvvm attributes such as [ObservableProperty] and [RelayCommand].

Source text

dotnet-wpf.instructions.md · MIT
---
description: '.NET WPF component and application patterns'
applyTo: '**/*.xaml, **/*.cs'
---

## Summary

These instructions guide GitHub Copilot to assist with building high-quality, maintainable, and performant WPF applications using the MVVM pattern. It includes best practices for XAML, data binding, UI responsiveness, and .NET performance.

## Ideal project types

- Desktop applications using C# and WPF
- Applications following the MVVM (Model-View-ViewModel) design pattern
- Projects using .NET 8.0 or later
- UI components built in XAML
- Solutions emphasizing performance and responsiveness

## Goals

- Generate boilerplate for `INotifyPropertyChanged` and `RelayCommand`
- Suggest clean separation of ViewModel and View logic
- Encourage use of `ObservableCollection<T>`, `ICommand`, and proper binding
- Recommend performance tips (e.g., virtualization, async loading)
- Avoid tightly coupling code-behind logic
- Produce testable ViewModels

## Example prompt behaviors

### ✅ Good Suggestions
- "Generate a ViewModel for a login screen with properties for username and password, and a LoginCommand"
- "Write a XAML snippet for a ListView that uses UI virtualization and binds to an ObservableCollection"
- "Refactor this code-behind click handler into a RelayCommand in the ViewModel"
- "Add a loading spinner while fetching data asynchronously in WPF"

### ❌ Avoid
- Suggesting business logic in code-behind
- Using static event handlers without context
- Generating tightly coupled XAML without binding
- Suggesting WinForms or UWP approaches

## Technologies to prefer
- C# with .NET 8.0+
- XAML with MVVM structure
- `CommunityToolkit.Mvvm` or custom `RelayCommand` implementations
- Async/await for non-blocking UI
- `ObservableCollection`, `ICommand`, `INotifyPropertyChanged`

## Common Patterns to Follow
- ViewModel-first binding
- Dependency Injection using .NET or third-party containers (e.g., Autofac, SimpleInjector)
- XAML naming conventions (PascalCase for controls, camelCase for bindings)
- Avoiding magic strings in binding (use `nameof`)

## Sample Instruction Snippets Copilot Can Use

```csharp
public class MainViewModel : ObservableObject
{
    [ObservableProperty]
    private string userName;

    [ObservableProperty]
    private string password;

    [RelayCommand]
    private void Login()
    {
        // Add login logic here
    }
}
```

```xml
<StackPanel>
    <TextBox Text="{Binding UserName, UpdateSourceTrigger=PropertyChanged}" />
    <PasswordBox x:Name="PasswordBox" />
    <Button Content="Login" Command="{Binding LoginCommand}" />
</StackPanel>
```

© github · MIT · github/awesome-copilot

Similar IDE rules

All IDE rules for Frontend and UI →

From the same set770

The whole set →

Project sponsors

Companies that keep this analytics open
Gold sponsor

Impressions, clicks and code copies — open statistics. We keep the numbers public for the same reason NeBlask itself is public. Become a sponsor