Repository navigation
Scrolling and Virtualization
English | Русский
MarkdownViewer has no scroll bars of its own. It lives inside the scrolling you already have and
creates controls only for the blocks that are visible through every scrolling container around it.
The other blocks exist as light models: selection, copying, search and the table of contents work with
the whole document anyway.
The usual case: one document fills a pane.
A window or a user control:
<ScrollViewer>
<md:MarkdownViewer Markdown="{Binding Text}" Margin="24,16" />
</ScrollViewer>The viewer can stand on a page next to other content, with one scroll bar for everything. Only the visible part of the document is created, even when the viewer is much taller than the window.
A window or a user control:
<ScrollViewer>
<StackPanel Margin="24,16">
<TextBlock Text="{Binding Title}" FontSize="24" />
<md:MarkdownViewer Markdown="{Binding Body}" />
<Button Content="Reply" HorizontalAlignment="Left" />
</StackPanel>
</ScrollViewer>A chat or a feed: a viewer per message inside a virtualized list. The list creates only visible messages, and a long message creates only its visible blocks.
A window or a user control:
<ItemsControl ItemsSource="{Binding Messages}"
VirtualizingPanel.IsVirtualizing="True"
VirtualizingPanel.ScrollUnit="Pixel"
ScrollViewer.CanContentScroll="True">
<ItemsControl.Template>
<ControlTemplate TargetType="ItemsControl">
<ScrollViewer CanContentScroll="True">
<ItemsPresenter />
</ScrollViewer>
</ControlTemplate>
</ItemsControl.Template>
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<VirtualizingStackPanel />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<md:MarkdownViewer DocumentKey="{Binding Id}" Markdown="{Binding Text}" Margin="8" />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>Keep VirtualizingPanel.ScrollUnit="Pixel": scrolling to a source line, a range or an anchor moves the
scroll position by pixels.
Give each message its DocumentKey. With VirtualizingPanel.VirtualizationMode="Recycling" the list
hands the viewer of a message that scrolled away to another message, and without a key the selection and
the widget state of the old message would move into the new one — see
Live Preview.
When new content comes at the end — an answer of a model, a feed of messages, a log — it is handy to keep
the scrolling at the edge. StickyScroll.Edge on a ScrollViewer of your application sticks it to an
edge: Bottom to the bottom, Top to the top when new content comes at the start. While the scrolling
is stuck, it returns to the edge however the content changes.
The scrolling comes unstuck when it is moved away from the edge — you can read older content, and new
chunks do not pull you down — and sticks again when it is brought back to the edge. With
StickyScroll.CanUnstick="False" it stays at the edge always. StickyScroll.IsStuck — read-only — tells
whether it is stuck now: for example, to show a «to the latest» button.
A window or a user control
(xmlns:md="https://github.com/porohkun/Beresta.Markdown.Wpf" on the root element):
<ScrollViewer md:StickyScroll.Edge="Bottom" md:StickyScroll.CanUnstick="True">
<md:MarkdownViewer Markdown="{Binding Text}" Margin="24,16" />
</ScrollViewer>In a virtualized list the same properties go on the ScrollViewer from the template of the list.
Without a scrolling container around it, the viewer creates all blocks and takes the height of the whole document. That is fine for short texts: a tooltip, a card, a dialog.
Wide tables and code blocks scroll sideways on their own but pass the mouse wheel to the page, so the
document keeps scrolling while the pointer is over them; Shift + wheel scrolls them sideways. A widget
of yours with its own ScrollViewer gets the same behavior with one attached property.
Your widget template (see Extensions):
<ScrollViewer HorizontalScrollBarVisibility="Auto"
VerticalScrollBarVisibility="Disabled"
md:NestedScroll.PassWheelToParent="True">
<TextBlock Text="{Binding Wide}" />
</ScrollViewer>A new Markdown value is applied as edits: unchanged blocks keep their controls and measured heights,
and the visible part does not jump when the text changes above it — see Live Preview.
Beresta.Markdown.Wpf · Issues · MIT License
Basics
- Getting Started
- How It Renders
- Supported Markdown
- Settings and Hooks
- Scrolling and Virtualization
- Comparison
Working with Text
Appearance
Integration
- Application Links
- Images
- Untrusted Text
- Task Lists
- Source Lines and Two Panes
- Coordinates
- Live Preview
Editing
Your Own Syntax
Ready-made Extensions
Основы
- Начало работы
- Как рисует вьюер
- Что поддерживается
- Настройки и перехват
- Прокрутка и виртуализация
- Сравнение
Работа с текстом
Оформление
Встраивание в приложение
- Ссылки приложения
- Картинки
- Чужой текст
- Списки задач
- Строки исходника и две панели
- Координаты
- Живой предпросмотр
Правка
Свой синтаксис
Готовые расширения