Page Index Toggle Pages: 1 [2]  Send TopicPrint
Hot Topic (More than 10 Replies) Inherit from DiagramLink (Read 13981 times)
Pontius
Junior Member
**
Offline


I love YaBB 1G - SP1!

Posts: 51
Joined: May 13th, 2011
Re: Inherit from DiagramLink
Reply #15 - Nov 21st, 2011 at 6:18pm
Print Post  
Hi Stoyo,

I still have AutoRoute enabled because disabling and enabling again had some side effects.

I tried your second proposal and changed the code as follows:


Code
Select All
    if (item.InnerControlPoints.Count > 0 && ControlPoints.Count > 1)
    {
        Point firstPoint = ControlPoints[0];
        Point lastPoint = ControlPoints[ControlPoints.Count - 1];

        ControlPoints.Clear();
        ControlPoints.Add(firstPoint);
        for (int i = 0; i < item.InnerControlPoints.Count; i++)
        {
            ControlPoints.Add(item.InnerControlPoints[i]);
        }
        ControlPoints.Add(lastPoint);

        //// SegmentCount can only be changed when AutoRoute == false
        //// Set diagram.RouteLinks to false and back to true in
        //SegmentCount = (short)(item.InnerControlPoints.Count + 1);

        //ControlPoints[0] = firstPoint;
        //ControlPoints[ControlPoints.Count - 1] = lastPoint;

        //for (int i = 0; i < item.InnerControlPoints.Count; i++)
        //{
        //    ControlPoints[i + 1] = item.InnerControlPoints[i];
        //}
    }
 



But immediatedly after setting the ControlPoints this way and before having a chance to call UpdateFromPoints(false, true) I get an OnSizeChanged() event with some slightly different values in ControlPoints.GetArray().

How can I avoid that the Mindfusion tool changes my values?

Regards,
Pontius
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Inherit from DiagramLink
Reply #16 - Nov 21st, 2011 at 6:50pm
Print Post  
Hi,

Are you sure there isn't anything else called between the control point assignments and the UpdateFromPoints call? I'll believe it only if you email me a test project that demonstrates that Smiley (from the email icon on the left)

Stoyan
  
Back to top
 
IP Logged
 
Pontius
Junior Member
**
Offline


I love YaBB 1G - SP1!

Posts: 51
Joined: May 13th, 2011
Re: Inherit from DiagramLink
Reply #17 - Dec 5th, 2011 at 3:45pm
Print Post  
Hi Stoyan,

I found out the reason for this unanticipated behaviour.

When I exit my View (which contains the Diagram) and create it again the old view still exists in the background.
Moreover I never get rid of the old Views and in the end I have a relation between one model and several views with just one view up to date and its Diagram beeing displayed.

Regarding the code in your example http://mindfusion.eu/Forum/YaBB.pl?board=wpfdg_disc;action=display;num=130641288...:

Code
Select All
private void OnDataItemsChanged(


INotifyCollectionChanged oldItems,


INotifyCollectionChanged newItems)

{


if (oldItems != null)


{



oldItems.CollectionChanged -= DataItemsCollectionChanged;



ClearAll();


}


if (newItems != null)


{



newItems.CollectionChanged += DataItemsCollectionChanged;



AddItems(DataItems);


}

}
 



I found out that the case (newItems != null) happens everytime I create the View but the other case (oldItems != null) never happens when I close the View. In the end of the day the gac never deletes an old View because there is still a subscription for the eventhandler. My current View containing the real Diagram is disturbed by obsolete instances of old Views that still exist.

Do you have any idea why I only get OnDataItemsChanged with newItems and never OnDataItemsChanged with oldItems?
Or do you have a suggestion for a workaround?
Is it a simple beginner's mistake?

Thanks and regards,
Pontius
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Inherit from DiagramLink
Reply #18 - Dec 5th, 2011 at 5:43pm
Print Post  
Yep, event handlers are an actual reference from the event source to the target, so they will prevent garbage collection. You should get a non-null oldItems when you set DataItems to some value. Are you assigning a different collection to DataItems when closing views? Something like

boundDiagram.DataItems = null;

or

boundDiagram.DataItems = new BindingList<...>();

Alternatively you could be more explicit and remove the handlers from some kind of Close() or Dispose() method, and then call that method when closing views.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Pontius
Junior Member
**
Offline


I love YaBB 1G - SP1!

Posts: 51
Joined: May 13th, 2011
Re: Inherit from DiagramLink
Reply #19 - Dec 6th, 2011 at 2:01pm
Print Post  
Hi Stoyan.

to work around the situation I implemented now:
Code
Select All
        private void UserControl_Unloaded(object sender, RoutedEventArgs e)
        {
            INotifyCollectionChanged not = GetValue(DataItemsProperty) as INotifyCollectionChanged;
            not.CollectionChanged -= DataItemsCollectionChanged;
        }
 



So I did by hand what I would have expected to work automatically.

I also removed the ClearAll() function call in
Code
Select All
        private void OnDataItemsChanged(INotifyCollectionChanged oldItems, INotifyCollectionChanged newItems)
        {
            if (oldItems != null)
            {
                oldItems.CollectionChanged -= DataItemsCollectionChanged;
//                ClearAll();
            }
            if (newItems != null)
            {
                newItems.CollectionChanged += DataItemsCollectionChanged;
                AddItems(DataItems);
            }
        }
 



because it removes not only the items of my Diagram but also the items in my model which I definetly do not want to be deleted. I wonder how the implementation with a ClearAll() can work without destroying the model data too.

Regards,
Pontuis
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Inherit from DiagramLink
Reply #20 - Dec 6th, 2011 at 6:39pm
Print Post  
Hi,

Why would you expect that to happen automatically? The framework cannot guess if you don't intend to use the control instance anymore, even if it has been removed from the WPF visual tree. E.g. you might be just moving it from one parent control to another.

Regarding ClearAll, do you perhaps handle some Diagram events to update the model data from diagram changes, such as ItemRemoved? You might have to detach these event handlers too to prevent ClearAll from updating your model.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Pontius
Junior Member
**
Offline


I love YaBB 1G - SP1!

Posts: 51
Joined: May 13th, 2011
Re: Inherit from DiagramLink
Reply #21 - Dec 9th, 2011 at 12:14pm
Print Post  
Hi Stoyan,

you are right. It can not happen automatically.

Regarding ClearAll() your hint caused me to implement the following which works:
Code
Select All
                diagram.LinkDeleted -= new LinkEventHandler(diagram_LinkDeleted);
                diagram.NodeDeleted -= new NodeEventHandler(diagram_NodeDeleted);
                diagram.ClearAll();
 



Thanks and regards,
Pontius
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1 [2] 
Send TopicPrint