Skip to content

Commit

Permalink
Implemented INotifyPropertyChanged on DropHintData to avoid WPF bindi…
Browse files Browse the repository at this point in the history
…ng leak
  • Loading branch information
bsundsbo committed Apr 2, 2024
1 parent ee96d8e commit a6325ce
Showing 1 changed file with 37 additions and 3 deletions.
40 changes: 37 additions & 3 deletions src/GongSolutions.WPF.DragDrop/DropHintData.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
namespace GongSolutions.Wpf.DragDrop;

using System.ComponentModel;
using System.Runtime.CompilerServices;
using JetBrains.Annotations;

/// <summary>
/// Data presented in drop hint adorner.
/// </summary>
public class DropHintData
public class DropHintData : INotifyPropertyChanged
{
private DropHintState hintState;
private string hintText;

public DropHintData(DropHintState hintState, string hintText)
{
this.HintState = hintState;
Expand All @@ -15,10 +22,37 @@ public DropHintData(DropHintState hintState, string hintText)
/// The hint text to display to the user. See <see cref="IDropInfo.DropHintText"/>
/// and <see cref="IDropHintInfo.DropHintText"/>.
/// </summary>
public string HintText { get; set; }
public string HintText
{
get => this.hintText;
set
{
if (value == this.hintText) return;
this.hintText = value;
this.OnPropertyChanged();
}
}

/// <summary>
/// The hint state to display different colors for hints. See <see cref="IDropInfo.DropTargetHintState"/>
/// and <see cref="IDropHintInfo.DropTargetHintState"/>.
/// </summary>
public DropHintState HintState { get; set; }
public DropHintState HintState
{
get => this.hintState;
set
{
if (value == this.hintState) return;
this.hintState = value;
this.OnPropertyChanged();
}
}

public event PropertyChangedEventHandler PropertyChanged;

[NotifyPropertyChangedInvocator]
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}

0 comments on commit a6325ce

Please sign in to comment.