Kryptos-FR / markdig.wpf

A WPF library for xoofx/markdig https://github.com/xoofx/markdig
MIT License
159 stars 50 forks source link

Feature request: Ability to customize scroll bar visibility #38

Closed alexrp closed 4 years ago

alexrp commented 4 years ago

With a RichTextBox, you can change HorizontalScrollBarVisibility/VerticalScrollBarVisibility to customize the scroll bar's visibility. It doesn't appear that there's an equivalent on MarkdownViewer.

Kryptos-FR commented 4 years ago

The default theme for MardownViewer has a control template with FlowDocumentScrollViewer setting the vertical scrollbar visibility to Auto. You can override it by providing your own template.

Taking by example the MainWindow.xaml from the sample project (some lines omitted for clarity):

<Window x:Class="Markdig.Wpf.SampleApp.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:markdig="clr-namespace:Markdig.Wpf;assembly=Markdig.Wpf">
  <FrameworkElement.Resources>
    <Style TargetType="markdig:MarkdownViewer">
      <Setter Property="Template">
        <Setter.Value>
          <ControlTemplate TargetType="markdig:MarkdownViewer">
            <FlowDocumentScrollViewer Document="{TemplateBinding Document}"
                                      ScrollViewer.HorizontalScrollBarVisibility="Visible"
                                      ScrollViewer.VerticalScrollBarVisibility="Visible" />
          </ControlTemplate>
        </Setter.Value>
      </Setter>
    </Style>
  </FrameworkElement.Resources>
  <DockPanel>
    <markdig:MarkdownViewer x:Name="Viewer"/>
  </DockPanel>
</Window>
alexrp commented 4 years ago

That worked, thanks!