We have a dependency property on a custom control that is called OnChannelOneAndTwoPopupIsOpen and it has a property changed callback. In this callback the ChannelOneAndTwoPopup.IsOpen property is set to true. Sometimes when this value changes to true our application crashes with the exception message "The root Visual of a VisualTarget cannot have a parent." The code is below for reference.
Does anyone know how to fix this? All we are doing is setting the popup's IsOpen property to true. I haven't been able to reproduce it but it keeps happening to one of our customers and I'd like to be able to figure this out and get it fixed. Any help would be greatly appreciated.
public static readonly DependencyProperty ChannelOneAndTwoPopupIsOpenProperty = DependencyProperty.Register(
"ChannelOneAndTwoPopupIsOpen", typeof(bool), typeof(SessionTrendChart),
new FrameworkPropertyMetadata(default(bool), FrameworkPropertyMetadataOptions.BindsTwoWayByDefault,
OnChannelOneAndTwoPopupIsOpenChanged));
public bool ChannelOneAndTwoPopupIsOpen
{
get => (bool) GetValue(ChannelOneAndTwoPopupIsOpenProperty);
set => SetValue(ChannelOneAndTwoPopupIsOpenProperty, value);
}
private static void OnChannelOneAndTwoPopupIsOpenChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
if (e.OldValue == e.NewValue) return;
if (d is SessionTrendChart control && e.NewValue is bool channelOneAndTwoPopupIsOpen)
control.OnChannelOneAndTwoPopupIsOpenChanged(channelOneAndTwoPopupIsOpen);
}
protected virtual void OnChannelOneAndTwoPopupIsOpenChanged(bool channelOneAndTwoPopupIsOpen)
{
if (ChannelOneAndTwoFiltersPopup == null || ChannelThreeAndFourFiltersPopup == null)
return;
if (channelOneAndTwoPopupIsOpen)
{
ChannelOneAndTwoFiltersPopup.IsOpen = true;
ChannelThreeAndFourFiltersPopup.IsOpen = false;
}
}
