Skip to content

Commit fa95c06

Browse files
authored
Merge pull request #624 from spdjudd/master
Fix ComboBoxPopup leak
2 parents 7031db0 + 30ca5e9 commit fa95c06

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

MaterialDesignThemes.Wpf/ComboBoxPopup.cs

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -187,16 +187,24 @@ public bool ClassicMode
187187
public ComboBoxPopup()
188188
{
189189
CustomPopupPlacementCallback = ComboBoxCustomPopupPlacementCallback;
190+
var childPropertyDescriptor = DependencyPropertyDescriptor.FromProperty(ComboBoxPopup.ChildProperty, typeof(ComboBoxPopup));
191+
EventHandler childChangedHandler = (sender, x) =>
192+
{
193+
if (PopupPlacement != ComboBoxPopupPlacement.Undefined)
194+
{
195+
UpdateChildTemplate(PopupPlacement);
196+
}
197+
};
190198

191-
DependencyPropertyDescriptor.FromProperty(ComboBoxPopup.ChildProperty, typeof(ComboBoxPopup))
192-
.AddValueChanged(this,
193-
delegate
194-
{
195-
if (PopupPlacement != ComboBoxPopupPlacement.Undefined)
196-
{
197-
UpdateChildTemplate(PopupPlacement);
198-
}
199-
});
199+
Loaded += (sender, args) =>
200+
{
201+
childPropertyDescriptor.AddValueChanged(this, childChangedHandler);
202+
};
203+
204+
Unloaded += (sender, args) =>
205+
{
206+
childPropertyDescriptor.RemoveValueChanged(this, childChangedHandler);
207+
};
200208
}
201209

202210
private void SetupBackground(IEnumerable<DependencyObject> visualAncestry)

0 commit comments

Comments
 (0)