Skip to content

Commit 45a5504

Browse files
authored
Fixes #1133 (#1142)
Fixing memory leak from ComboBoxPopup registering itself as a DP callback. Switching to simply overriding the OnPropertyChanged method to avoid accidently capturing our instance in the delegate.
1 parent b009263 commit 45a5504

File tree

1 file changed

+7
-13
lines changed

1 file changed

+7
-13
lines changed

MaterialDesignThemes.Wpf/ComboBoxPopup.cs

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -185,24 +185,18 @@ public bool ClassicMode
185185
public ComboBoxPopup()
186186
{
187187
CustomPopupPlacementCallback = ComboBoxCustomPopupPlacementCallback;
188-
var childPropertyDescriptor = DependencyPropertyDescriptor.FromProperty(ComboBoxPopup.ChildProperty, typeof(ComboBoxPopup));
189-
EventHandler childChangedHandler = (sender, x) =>
188+
}
189+
190+
protected override void OnPropertyChanged(DependencyPropertyChangedEventArgs e)
191+
{
192+
base.OnPropertyChanged(e);
193+
if (e.Property == ChildProperty)
190194
{
191195
if (PopupPlacement != ComboBoxPopupPlacement.Undefined)
192196
{
193197
UpdateChildTemplate(PopupPlacement);
194198
}
195-
};
196-
197-
Loaded += (sender, args) =>
198-
{
199-
childPropertyDescriptor.AddValueChanged(this, childChangedHandler);
200-
};
201-
202-
Unloaded += (sender, args) =>
203-
{
204-
childPropertyDescriptor.RemoveValueChanged(this, childChangedHandler);
205-
};
199+
}
206200
}
207201

208202
private void SetupBackground(IEnumerable<DependencyObject> visualAncestry)

0 commit comments

Comments
 (0)