Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Refreshing the whole diagram (Read 2257 times)
milosa
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 11
Joined: Mar 16th, 2017
Refreshing the whole diagram
May 23rd, 2017 at 8:38am
Print Post  
Hello,

We have the requirement to have a setting which when changed will affect potentially all the displayed nodes and links on the diagram.
What we would like to do is to instead of raising the events from every single node and link that something has changed, do a complete redraw of the diagram (and we are aware that this is a potentially very expensive operation).

We tried with the Invalidate method on the Diagram class but this doesn't really cause the whole diagram to be redrawn. So even if for example a color of come node has changed in the view model, it's not read and refreshed in the diagram.

Is there a way to achieve this and what should we use in that case?

Thanks!
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3147
Joined: Oct 19th, 2005
Re: Refreshing the whole diagram
Reply #1 - May 23rd, 2017 at 9:18am
Print Post  
Hi,

Try calling DiagramItem.Repaint(), from a loop if you need it for all items. It calls InvalidateVisual on the item and its adorner, which should cause WPF to refresh the respective parts of the visual tree from its next layout cycle.

Regards,
Slavcho
  
Back to top
 
IP Logged
 
milosa
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 11
Joined: Mar 16th, 2017
Re: Refreshing the whole diagram
Reply #2 - May 23rd, 2017 at 11:20am
Print Post  
Hello Slavcho,

I just tried with Repaint() that you suggested, and again the break points in the getters of the view models are not hit and the diagram is not changed.

Any other suggestion that I could try?
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3147
Joined: Oct 19th, 2005
Re: Refreshing the whole diagram
Reply #3 - May 23rd, 2017 at 4:30pm
Print Post  
Hi,

I've verified our Draw method gets called shortly after you call Repaint, but it seems WPF caches results of binding expressions and does not call the bound getter, unless there was PropertyChanged raised to mark the binding as dirty I guess. My test was with Text property -

Code
Select All
class BindTestModel : INotifyPropertyChanged
{
	public string TestValue
	{
		get { return testValue; }
		set
		{
			testValue = value;
			//if (PropertyChanged != null)
			//	PropertyChanged(this, new PropertyChangedEventArgs("TestValue"));
		}
	}

	private string testValue = "";

	public event PropertyChangedEventHandler  PropertyChanged;
}

var model1 = new BindTestModel();
var binding1 = new Binding("TestValue")
{
	Source = model1,
	Mode = BindingMode.OneWay
};
var node = diagram.Factory.CreateShapeNode(10, 10, 100, 100);
node.SetBinding(ShapeNode.TextProperty, binding1);
node.Tag = model1;

private void OnNodeClicked(object sender, NodeEventArgs e)
{
	var model1 = e.Node.Tag as BindTestModel;
	model1.TestValue = "new value";
	BindingOperations.GetBindingExpressionBase(
		e.Node, ShapeNode.TextProperty).UpdateTarget();
	e.Node.Repaint(false);
} 



So UpdateTarget() updates the binding too and it shows new value. If you comment out UpdateTarget, ShapeNode.Draw gets to the part where it draws the bound Text property, but that just returns cached old value without getting inside model's getter. I'm not sure why you'd want to suppress the PropertyChanged events, they will only mark the expressions as dirty and will lead to a future redraw, but won't repaint immediately after each change.

Regards,
Slavcho
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint