Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Questions node brush and selection (Read 4268 times)
baba
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 16
Joined: Jan 20th, 2010
Questions node brush and selection
Jul 30th, 2010 at 12:17pm
Print Post  
Hi all,
here I am with a couple of questions that came after I tried for a while to do what seems to be a trivial task and not succeding in it, anyway... here it goes:

I have a Diagram which should not be edited by the end user, but only viewed. The user cannot directly edit diagram items' text or layout (size, position etc.) properties. Instead the user should be able to select a node and execute some other actions which should actually drive to some modifications to the Diagram (e.g.: a node would change its color).
Besides, the user should be able to "select" the node by left-clicking on it.

I started by the most general requirement and I set the Diagram AllowInplaceEdit property to "false". But this prevents the user from even selecting the node, so the first question is: how to obtain node selection in a Diagram which does not allow inplace edit?

Then I tried and implement the second requirement, that is to say I've tried to change the color of a node programmatically, through this:

// from green to white
blockNode.Brush = new SolidColorBrush(Colors.White);

... but no, no way to make this thing happen. I only succedeed in changing the node border color by doing:
blockNode.Pen = new Pen(new SolidColorBrush(Colors.White));

or:

blockNode.Stroke = new SolidColorBrush(Colors.White);

And this is the second question, why the node background color does not change?

Thanks in advance,
baba.
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Questions node brush and selection
Reply #1 - Jul 30th, 2010 at 12:48pm
Print Post  
Hi Baba,

Disabling AllowInplaceEdit won't stop the user selecting items. That might happen if you set Behavior = DoNothing. In that case you will get only NodeClicked events from which you might change the color, but not NodeSelected.

Instead of DoNothing, you could use the Modify behavior which lets users select and modify items. To prevent item modification, handle the NodeModifying and LinkModifying events and call e.CancelDrag().

The Brush property might not work if you have created a custom node template where no visual element has a TemplateBinding to Brush.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
baba
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 16
Joined: Jan 20th, 2010
Re: Questions node brush and selection
Reply #2 - Jul 30th, 2010 at 1:31pm
Print Post  
Hi Stoyo,
yes you're right about the behavior being the point, not the AllowInplaceEdit property as I stated.
That said, I almost solved the first problem. I say "almost" because I've been following your directions and subscrived the modify validation events and called "e.CancelDrag()" inside them. Everything seems to work as expected BUT if I do the following:

- select a node (by the way: a simple class derived from ShapeNode, but setting node.Brush not working yet);
- left click on the inner-central selection handle;
- start to drag: in this case, in fact, the node is moved and, sometimes, even incoming links are.

Could you try and see if it's a bug or it's just me?

We're using v. 1.7 full here, no trial.

Cheers,
baba.
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Questions node brush and selection
Reply #3 - Jul 30th, 2010 at 1:51pm
Print Post  
Hi Baba,

It works fine for me. Does your class override the UpdateDrag method by any chance? You might also try implementing that by setting EnabledHandles = None instead of handling NodeModifying.

I don't have any idea why Brush would not work if your derived ShapeNode uses the standard template. What Shape have you assigned to that node?

Stoyan
  
Back to top
 
IP Logged
 
baba
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 16
Joined: Jan 20th, 2010
Re: Questions node brush and selection
Reply #4 - Jul 30th, 2010 at 2:58pm
Print Post  
Hi Stoyo,
have you tried with more than just one diagram item?

Here's a MainPage for you to see, first the XAML:

Code
Select All
<UserControl x:Class="CancelDragTest.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:my="clr-namespace:MindFusion.Diagramming.Silverlight;assembly=MindFusion.Diagramming.Silverlight"
    mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480">
    <Grid x:Name="LayoutRoot">

        <my:Diagram
            x:Name="diagramControl"
            Behavior="Modify"
            AllowInplaceEdit="False"
            DefaultShape="Rectangle"
            BackBrush="WhiteSmoke"
            LinkHeadShape="Triangle"
            LinkCrossings="Arcs" />

    </Grid>
</UserControl>
 



then the code-behind:

Code
Select All
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using MindFusion.Diagramming.Silverlight;

namespace CancelDragTest
{
    public partial class MainPage : UserControl
    {
        public MainPage()
        {
            InitializeComponent();

            ShapeNode newNode = new ShapeNode(diagramControl);
            newNode.Bounds = new Rect(0, 0, 100, 100);

            ShapeNode destinationNode = new ShapeNode(diagramControl);

            destinationNode.Bounds = new Rect(newNode.Bounds.Right + 100, newNode.Bounds.Bottom + 100, 200, 200);

            diagramControl.Nodes.Add(newNode);
            diagramControl.Nodes.Add(destinationNode);
            DiagramLink connection = new DiagramLink(diagramControl);

            connection.Origin = newNode;
            connection.Destination = destinationNode;
            diagramControl.Links.Add(connection);

            diagramControl.NodeModifying += new NodeValidationEventHandler(diagramControl_NodeModifying);
            diagramControl.LinkModifying += new LinkValidationEventHandler(diagramControl_LinkModifying);
        }

        void diagramControl_LinkModifying(object sender, LinkValidationEventArgs e)
        {
            e.CancelDrag();
        }

        void diagramControl_NodeModifying(object sender, NodeValidationEventArgs e)
        {
            e.CancelDrag();
        }
    }
}

 



I've done the following tests:

1. select _only_ the first node, the small one, and try to drag it somewhere, starting the dragging action from some point inside the node but not a selection handle. Result: the node cannot be moved, the link stays in place, too. So far so good...

2. select _only_ the first node, the small one, and tried to drag it somewhere, starting the dragging action from one of the election handles. Result: the node cannot be moved, the link tail _moves_.

3. select the small node and the link or, as you prefer, both the nodes then start dragging a node from _any_ point inside it. Result: the node moves, the link too.

Can you reproduce this behavior?

Cheers,
baba.
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Questions node brush and selection
Reply #5 - Jul 31st, 2010 at 4:16pm
Print Post  
Hi Baba,

Ok, we have a SelectionMoving event in other controls that lets you stop moving multiple items, but we haven't ported it to Silverlight yet. You can use this custom behavior instead to allow selecting items (by clicking them or ctrl+click) but not moving them:

Code
Select All
diagram.CustomBehavior = new MyBehavior(diagram);

public class MyBehavior : DrawLinksBehavior
{
	public MyBehavior(Diagram diagram) : base(diagram) { }

	protected override void OnMouseMove(MouseEventArgs e) {}
} 



Stoyan
  
Back to top
 
IP Logged
 
baba
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 16
Joined: Jan 20th, 2010
Re: Questions node brush and selection
Reply #6 - Aug 1st, 2010 at 2:44pm
Print Post  
Hi Stoyo,
  it seems to work now. Hope further tests will confirm this, thanks.

Cheers,
baba.
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint