Skip to content

Getting Started

Porohkun edited this page Oct 23, 2026 · 10 revisions

English | Русский

The viewer is a library: you add it to a WPF application, connect its theme once and put MarkdownViewer where the document should be.

Requirements: .NET 7 or later (net7.0-windows) with WPF.

Install

As a NuGet package.

Terminal, in the folder of your application project:

dotnet add package Beresta.Markdown.Wpf

IntelliSense documentation comes in English and Russian: Visual Studio with a Russian interface shows the Russian one.

To edit Markdown right where it is drawn, add the second package, Beresta.Markdown.Wpf.Editor — see Editor.

Connect the theme

The viewer draws blocks with the templates of its theme, Themes/Generic.xaml. Merge it into the application resources once: the theme keys work only from there. Without it the viewer shows a hint with this address instead of the document and writes the same to Trace.

App.xaml, the application resources:

<Application.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="pack://application:,,,/Beresta.Markdown.Wpf;component/Themes/Generic.xaml" />
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
</Application.Resources>

Your own dictionary that overrides theme keys goes after this one — see Theming.

Show a document

The viewer has no scroll bars of its own: put it into a ScrollViewer. Other places for it are in Scrolling and Virtualization. One XAML namespace, xmlns:md="https://github.com/porohkun/Beresta.Markdown.Wpf", gives every type of the library: the viewer, ready-made extensions, presenters — the examples of this wiki use it.

MainWindow.xaml, the whole window:

<Window x:Class="YourApp.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:md="https://github.com/porohkun/Beresta.Markdown.Wpf"
        Title="Markdown" Width="800" Height="600">
    <ScrollViewer>
        <md:MarkdownViewer x:Name="Viewer" Margin="24,16" />
    </ScrollViewer>
</Window>

MainWindow.xaml.cs, in the constructor after InitializeComponent():

Viewer.Markdown = """
    # Hello

    This is **Markdown** in a *WPF* window.

    - [x] theme connected
    - [ ] read the wiki
    """;

Markdown can be bound: Markdown="{Binding Text}". A new value is applied to the shown document as edits, so a text that changes often is fine — see Live Preview.

The viewer does not set the font and the color of the text: they come from your window. The theme sets only sizes, margins and accents.

Next steps

Beresta.Markdown.Wpf

Basics

Working with Text

Appearance

Integration

Editing

Your Own Syntax

Ready-made Extensions


По-русски

Основы

Работа с текстом

Оформление

Встраивание в приложение

Правка

Свой синтаксис

Готовые расширения

Clone this wiki locally