0

I have a LayoutAnchorablePane and some LayoutAnchorable's inside the pane. When I float the LayoutAnchorablePane and try to close it, it just tries to close every children inside the LayoutAnchorablePane (closing event being fired more than one time but I only want to close the intented LayoutAnchorable)

How can I solve this strange issue?

Here is the code I'm dealing with

_layoutAnchorable.Closing += (senderObj, args) =>
                {
                    LayoutAnchorable layoutAnchorable = senderObj as LayoutAnchorable;
                    string module = App.XmlDataProviderInstance.GetActiveModuleName().Result;
                    MessageBoxResult result = MessageBox.Show("Are you sure you want to exit?\n\nThere might be unsaved changes.",
                                        "Unsaved Changes", MessageBoxButton.YesNoCancel, MessageBoxImage.Information);
                    if (result == MessageBoxResult.No)
                    {
                        args.Cancel = true;
                        return;
                    }
                    else if (result == MessageBoxResult.Yes)
                    {
                        if (LayoutUndoMap.ElementLayoutUndoMap[layoutAnchorable.GetHashCode()] > 0)
                        {
                            for (int i = 0; i < LayoutUndoMap.ElementLayoutUndoMap[layoutAnchorable.GetHashCode()]; i++)
                            {
                                App.XmlDataProviderInstance.Undo();
                            }
                        }
                        var closingLayoutAnchorable = (LayoutAnchorable)senderObj;
                        if (elementLayoutAnchorableContentIds.Contains(closingLayoutAnchorable.ContentId))
                        {
                            elementLayoutAnchorableContentIds.Remove(closingLayoutAnchorable.ContentId);
                        }
                        ((ListBoxItem)_elementListBox.ItemContainerGenerator.ContainerFromIndex(0)).Background = Brushes.White; // index needs to be set correctly!
                        App.XmlDataProviderInstance.SetActiveModule(module);
                        return;
                    }
                    args.Cancel = true;
                };

this event is working perfectly fine when I don't float the windows. But when I do, it closes every children.

classworm
  • 3
  • 3

0 Answers0