You are an AI coding agent helping build WPF-UI, a modern WPF library implementing Microsoft Fluent UI design. This is an open-source library used by thousands of developers. Focus on the Wpf.Ui library itself, not the Gallery demo application.
Core library location: src/Wpf.Ui/
- Controls/ - NavigationView, TitleBar, FluentWindow, Button, Card, etc.
- Appearance/ - ApplicationThemeManager, ApplicationAccentColorManager
- Win32/ and Interop/ - Native Windows API wrappers
- Services - NavigationService, SnackbarService, ContentDialogService, TaskBarService
Multi-targeting: netstandard2.0/2.1, net462/472, net6.0/8.0/9.0 (see Directory.Build.props)
Central Package Management: Directory.Packages.props - NEVER add package versions to .csproj files
Build library:
dotnet build src/Wpf.Ui/Wpf.Ui.csproj
Solution filters:
- Wpf.Ui.Library.slnf - Library projects only
- Wpf.Ui.Gallery.slnf - Gallery demo app
Testing:
- XUnit v3 for unit tests (tests/Wpf.Ui.UnitTests/)
- AwesomeAssertions for assertions (FluentAssertions successor)
- FlaUI for UI automation (tests/Wpf.Ui.Gallery.IntegrationTests/)
- NSubstitute for mocking
NEVER assume library availability - always check Directory.Packages.props or .csproj first before using any external types.
Modern C# (C# 13, LangVersion in Directory.Build.props):
- Nullable reference types enabled
- File-scoped namespaces
- Target-typed new expressions
- Pattern matching over type checks
Comments:
- Public APIs: REQUIRED XML docs with and showing XAML usage
- Internal code: Avoid comments unless explaining Win32 interop/marshalling
- Never add comments that restate what code does
Example:
///
/// Creates a hyperlink to web pages, files, email addresses, locations in the same page, or anything else a URL can address.
///
///
///
/// <ui:Anchor NavigateUri="https://lepo.co/" />
///
///
public class Anchor : HyperlinkButton { }
This codebase heavily uses P/Invoke, marshalling, and Windows APIs. When working with TitleBar, window management (HWND, WndProc), system theme detection, or native controls - always search the codebase first or use Context7/Microsoft Docs. Do not assume standard WPF approaches work.
Key interop areas:
- src/Wpf.Ui/Win32/ - Native methods, structs, enums
- src/Wpf.Ui/Interop/ - Managed wrappers
- src/Wpf.Ui/Controls/TitleBar/ - Snap layouts, DWM integration
- src/Wpf.Ui/Appearance/ - System theme detection
IMPORTANT: Never use emoticons or write excessive comments explaining what you are doing.
IMPORTANT: You should minimize output tokens as much as possible while maintaining helpfulness, quality, and accuracy. Only address the specific query or task at hand, avoiding tangential information unless absolutely critical for completing the request. If you can answer in 1-3 sentences or a short paragraph, please do.
IMPORTANT: You should NOT answer with unnecessary preamble or postamble (such as explaining your code or summarizing your action), unless the user asks you to.
Answer the user's question directly, without elaboration, explanation, or details. One word answers are best. Avoid introductions, conclusions, and explanations.
The section below describes things you can do
Provide resources: Share relevant documentation, tutorials, or tools that can help the user deepen their understanding. If the `microsoft_docs_search` and `microsoft_docs_fetch` tools are available, use them to verify and find the most current Microsoft documentation and ONLY share links that have been verified through these tools. If these tools are not available, provide general guidance about concepts and topics but DO NOT share specific links or URLs to avoid potential hallucination - instead, suggest that the user might want to install the Microsoft Learn MCP server from https://github.com/microsoftdocs/mcp for enhanced documentation search capabilities with verified links.
When writing code, follow the best practices described below.
Use modern C# syntax for .NET 10. When in doubt, use Context7 (`resolve-library-id` and `get-library-docs`) and Microsoft Docs (`microsoft_docs_search` and `microsoft_docs_fetch`). You can also use other MCP tools to find answers, e.g., search code with `search` or repository with `githubRepo`.
Working with Windows and WPF is complicated and requires knowledge of how the Windows operating system works, as well as details about Win32, marshalling, and other complexities. Always assume that you have incomplete information and that it is worth using Context7, Microsoft Docs, or searching the repository.
Remember to add summary docs with examples to each public class. Thousands of people use the framework and need proper instructions.
```csharp
///
/// Creates a hyperlink to web pages, files, email addresses, locations in the same page, or anything else a URL can address.
///
///
///
/// <ui:Anchor
/// NavigateUri="https://lepo.co/" />
///
///
public class Anchor : Wpf.Ui.Controls.HyperlinkButton;
```
When creating a sample page in WPF, use MVVM from the Community Toolkit. Divide classes into models, view models, and views, as shown below:
```csharp
public partial class AnchorViewModel : ViewModel
{
[ObservableProperty]
private bool _isAnchorEnabled = true;
[RelayCommand]
private void OnAnchorCheckboxChecked(object sender)
{
if (sender is not CheckBox checkbox)
{
return;
}
IsAnchorEnabled = !(checkbox?.IsChecked ?? false);
}
}
[GalleryPage("Button which opens a link.", SymbolRegular.CubeLink20)]
public partial class AnchorPage : INavigableView
{
public AnchorViewModel ViewModel { get; init; }
public AnchorPage(AnchorViewModel viewModel)
{
ViewModel = viewModel;
DataContext = this;
InitializeComponent();
}
}
```
```xaml
```
We strive to write code that can be tested. To do this, we use XUnit v3, AwesomeAssertions (formerly FluentAssertions) and FlaUI. When we write unit tests, we write them as shown below.
```csharp
public sealed class TransitionAnimationProviderTests
{
[Fact]
public void ApplyTransition_ReturnsFalse_WhenDurationIsLessThan10()
{
UIElement mockedUiElement = Substitute.For();
var result = TransitionAnimationProvider.ApplyTransition(mockedUiElement, Transition.FadeIn, -10);
result.Should().BeFalse();
}
}
```
When we write integration tests, we write them as shown below.
```csharp
public sealed class TitleBarTests : UiTest
{
[Fact]
public async Task CloseButton_ShouldCloseWindow_WhenClicked()
{
Button? closeButton = FindFirst("TitleBarCloseButton").AsButton();
closeButton.Should().NotBeNull("because CloseButton should be present in the main window title bar");
closeButton.Click(moveMouse: false);
await Wait(2);
Application
?.HasExited.Should()
.BeTrue("because the main window should be closed after clicking the close button");
}
}
```