Skip to content
This repository was archived by the owner on Mar 14, 2024. It is now read-only.

Adding HandleVerticalScrollEvents Dependency Property #44

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions src/Markdig.Wpf/MarkdownViewer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;

namespace Markdig.Wpf
{
Expand Down Expand Up @@ -35,11 +36,27 @@ public class MarkdownViewer : Control
public static readonly DependencyProperty PipelineProperty =
DependencyProperty.Register(nameof(Pipeline), typeof(MarkdownPipeline), typeof(MarkdownViewer), new FrameworkPropertyMetadata(PipelineChanged));

/// <summary>
/// Defines the <see cref="HandleVerticalScrollEvents"/> property.
/// </summary>
public static readonly DependencyProperty HandleVerticalScrollEventsProperty =
DependencyProperty.Register(nameof(HandleVerticalScrollEvents), typeof(bool), typeof(MarkdownViewer));

static MarkdownViewer()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(MarkdownViewer), new FrameworkPropertyMetadata(typeof(MarkdownViewer)));
}

public MarkdownViewer()
{
AddHandler(MouseWheelEvent, new MouseWheelEventHandler(OnVerticalScrollEventHandled), true);
}

private void OnVerticalScrollEventHandled(object sender, MouseWheelEventArgs e)
{
e.Handled = HandleVerticalScrollEvents;
}

/// <summary>
/// Gets the flow document to display.
/// </summary>
Expand Down Expand Up @@ -67,6 +84,15 @@ public MarkdownPipeline Pipeline
set { SetValue(PipelineProperty, value); }
}

/// <summary>
/// Gets or sets the handling of the vertical scroll events.
/// </summary>
public bool HandleVerticalScrollEvents
{
get { return (bool)GetValue(HandleVerticalScrollEventsProperty); }
set { SetValue(HandleVerticalScrollEventsProperty, value); }
}

private static void MarkdownChanged(object sender, DependencyPropertyChangedEventArgs e)
{
var control = (MarkdownViewer)sender;
Expand Down