Skip to content

Commit

Permalink
fix a memory leak. refs #80
Browse files Browse the repository at this point in the history
  • Loading branch information
whistyun committed Jan 4, 2024
1 parent 52963b8 commit 8d86aba
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions MdXaml/MarkdownScrollViewer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -375,12 +375,23 @@ public MarkdownScrollViewer()
ContextMenu = menu;


DependencyPropertyDescriptor
.FromProperty(FlowDocumentScrollViewer.DocumentProperty, typeof(FlowDocumentScrollViewer))
.AddValueChanged(this, OnDocumentChanged);
// Do not use DependencyPropertyDescriptor. This may cause memory leaks if used with low understanding.
//
// DependencyPropertyDescriptor
// .FromProperty(FlowDocumentScrollViewer.DocumentProperty, typeof(FlowDocumentScrollViewer))
// .AddValueChanged(this, OnDocumentChanged);
}

private void OnDocumentChanged(object sender, EventArgs handler)
protected override void OnPropertyChanged(DependencyPropertyChangedEventArgs e)
{
base.OnPropertyChanged(e);

if (e.Property == FlowDocumentScrollViewer.DocumentProperty)
OnDocumentChanged();
}


private void OnDocumentChanged()
{
if (Document is not null)
ScrollTo(Fragment, false);
Expand Down

0 comments on commit 8d86aba

Please sign in to comment.