Page Index Toggle Pages: [1] 2  Send TopicPrint
Hot Topic (More than 10 Replies) Changing ContentTemplate in C# (Read 13839 times)
Hai
Junior Member
**
Offline


I love YaBB 1G - SP1!

Posts: 63
Joined: Jan 7th, 2009
Changing ContentTemplate in C#
Feb 18th, 2009 at 2:25pm
Print Post  
Hi all
I’ve noticed a feature called “ContentTemplate” of the ShapeNode
1.
Can you please give me an example for the usage of this property in C#
2.
Can I change the template dinamically ?

Many thanks Cheesy
Hai
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Changing ContentTemplate in C#
Reply #1 - Feb 18th, 2009 at 2:31pm
Print Post  
Hi,

ShapeNode derives this property from ContentControl, and I don't think it's a good idea to touch it. You can create a user control and host it inside ControlNode objects if you need nodes that look very different from ShapeNode.

Stoyan
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Changing ContentTemplate in C#
Reply #2 - Feb 18th, 2009 at 2:35pm
Print Post  
Actually our developer thinks it's a good idea to let you provide a template with placeholders for the ShapeNode's Image and Text. We'll try to implement this in the 1.0.2 version ...
  
Back to top
 
IP Logged
 
Hai
Junior Member
**
Offline


I love YaBB 1G - SP1!

Posts: 63
Joined: Jan 7th, 2009
Re: Changing ContentTemplate in C#
Reply #3 - Feb 18th, 2009 at 4:08pm
Print Post  
Thank you Stoyan for the quick reply.

For now I will try to implement that workaround  you have suggested.

Do you have an estimation for when will the 1.0.2 version will be released?
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Changing ContentTemplate in C#
Reply #4 - Feb 19th, 2009 at 8:56am
Print Post  
It should be available in a few weeks.

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


I love YaBB 1G - SP1!

Posts: 63
Joined: Jan 7th, 2009
Re: Changing ContentTemplate in C#
Reply #5 - Feb 21st, 2009 at 12:52pm
Print Post  
Hi Stoyan
Thank you for that, I will look for that release.

I'm also trying to manipulate the border of the node using BorderThickness and BorderBrush but I do not see the effect in the visual display.
This is my code:

Thickness tmpThick = new Thickness(3, 3, 3, 3);
NewNode.BorderThickness = tmpThick;
NewNode.BorderBrush = new SolidColorBrush(Colors.Red);

What am I doing wrong ?
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Changing ContentTemplate in C#
Reply #6 - Feb 21st, 2009 at 1:06pm
Print Post  
Hi Hai,

If you see BorderThickness and BorderBrush, they are probably inherited from FrameworkElement and ShapeNodes does not use them. Instead, set the node.Pen property. Since v1.0.1 it is of the DiagramLite's Pen type, and provides its own Thickness property. This is mostly for compatibility with the other Mindfusion diagramming components. I suppose we could bind the FrameworkElement's properties to the ShapeNode.Pen attributes for the next release to make the interface more consistent with Silverlight.

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


I love YaBB 1G - SP1!

Posts: 63
Joined: Jan 7th, 2009
Re: Changing ContentTemplate in C#
Reply #7 - Feb 22nd, 2009 at 9:40am
Print Post  
Hi Stoyan

Thanks for your reply.
What I actually need is something to visually show a Valid/Invalid node.
So I thought about a thick red/green border but could not find a way to do it using pen...(any ideas ?)
I also thought of adding a small X or V icon. I drilled into the content of the node (into its internal grid) and added a small icon... but it didn't show on the UI. Is this approach possible ? any other options ?

+ I have a few more things that I cannot figure out…..

1. Is it possible to copy/paste a node using the clipboard ?

2. I added the ability to drag the entire workspace.  When I try to change the cursor in the application like
Cursor = Cursors.Hand;
It is changed in my application. When it first enters the diagram all is well but after clicking it is changed into an arrow, no matter what I do, like:
(fCartTst is my diagram)

    private void fCartTst_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
       {
           if (isDraggingWorkspace == true)
           {
               Cursor = Cursors.Hand;
           }
           else
           {
               //Disable free writing on the diagram
    fCartTst.Behavior = Behavior.DoNothing;
           }
       }

       private void fCartTst_MouseMove(object sender, MouseEventArgs e)
       {
           if (isDraggingWorkspace == true)
           {
               Cursor = Cursors.Hand;
           }
       }
3. The diagram have this property -  KeyDown="fCartTst_KeyDown"
This event does not fire.
Also tried that…
NewNode.KeyDown += new KeyEventHandler(NewNode_KeyDown);
Nothing fire. Any ideas ?

Hai
« Last Edit: Feb 22nd, 2009 at 10:49am by Hai »  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Changing ContentTemplate in C#
Reply #8 - Feb 22nd, 2009 at 11:48am
Print Post  
Hi Hai,

Doesn't this work?

Code
Select All
ShapeNode node = new ShapeNode(diagram);
node.Pen = new Pen(new SolidColorBrush(Colors.Red), 10);
diagram.Nodes.Add(node);
node.Bounds = new Rect(80, 80, 80, 80);
 



Stoyan
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Changing ContentTemplate in C#
Reply #9 - Feb 22nd, 2009 at 12:07pm
Print Post  
Regarding your other questions:

1. There is no clipboard support in Silverlight 2. For copying a single node, you can use the copy constructors we added to v1.0.1. For copying multiple nodes and links, we could add copy/paste methods to let you at least copy between diagram objects in the same Silverlight application.

2. Try also setting Diagram.Cursor.

3. You might have to TAB a few times to move the keyboard focus to the diagram. We'll also add a method to let you set it programmatically.

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


I love YaBB 1G - SP1!

Posts: 63
Joined: Jan 7th, 2009
Re: Changing ContentTemplate in C#
Reply #10 - Feb 22nd, 2009 at 1:52pm
Print Post  
Hi Stoyan

I've downloaded the 1.0.1 and everything looks better...  Grin

Can you please give me a sample code for using the copy constructors ? and pasting in the mouse position...

Thx

Hai
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Changing ContentTemplate in C#
Reply #11 - Feb 22nd, 2009 at 2:08pm
Print Post  
Hi Hai,

Your copy function might just save a reference to the ActiveItem, and the paste function could do something like this:

Code
Select All
if (itemToCopy is ShapeNode)
{
	ShapeNode node = itemToCopy as ShapeNode;
	ShapeNode copy = new ShapeNode(node);
	diagram.Items.Add(copy);
	copy.Bounds = new Rect(...); // based on mouse position
}
 



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


I love YaBB 1G - SP1!

Posts: 63
Joined: Jan 7th, 2009
Re: Changing ContentTemplate in C#
Reply #12 - Feb 23rd, 2009 at 12:01pm
Print Post  
Yup, it did 8)
Thx

I have 2 more questions regarding the "Ready Diagram" sample…
1.Is there a way to position picture & text via code (C#). I could not find the node's property -
<TextFormat>

<Alignment>1</Alignment>

<Flags>0</Flags>

<LineAlignment>1</LineAlignment>

<Trimming>1</Trimming>
</TextFormat>
2.When I save into the isolated storage a node with Image and then reload it from the isolated storage I lose the image. Any idea what is causing that ?

Oa, and one more thing
3. How can I strach the control ?
I've tryed
Height="Auto" VerticalAlignment="Stretch"
But it is still small unless I give it a fixed height, which is not good for different resolutions...


Many thanks for your support
Hai
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Changing ContentTemplate in C#
Reply #13 - Feb 23rd, 2009 at 1:37pm
Print Post  
1. TextFormat is not implemented yet, and that XML was saved from the Windows Forms version Smiley Anyway we'll try to implement support for templates in the next few days.

2. There is no support for encoding images in Siverlight, so we haven't implemented this. We got permission from Joe Stegman to use his PNGEncoder in DiagramLite, and will add image serialization to the next version

3. Are you applying these properties to the Diagram, or to the ScrollViewer?

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


I love YaBB 1G - SP1!

Posts: 63
Joined: Jan 7th, 2009
Re: Changing ContentTemplate in C#
Reply #14 - Feb 24th, 2009 at 8:52am
Print Post  
Thx Stoyan, I'll wait for the next release
Regarding 3. , I'm setting this on both controls:

<ItemsControl x:Name="MainRegion" Background="{x:Null}" Margin="0,0,0,0" HorizontalAlignment="Stretch" BorderBrush="{x:Null}" BorderThickness="0,0,0,0" >
                          
                          
                             <!--Row 1  WF WORKSPACE -->
                           <ScrollViewer x:Name="svDiagram" Width="Auto" Background="White" Height="Auto"
                               HorizontalAlignment="Stretch"
                               VerticalAlignment="Stretch"
                               Padding="0"
                               HorizontalScrollBarVisibility="Auto">                                <my:Diagram x:Name="fCartTst" Width="Auto" Height="Auto" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" ShowGrid="True" AlignToGrid="True" Background="White" Behavior="LinkShapes"
                                           AllowInplaceEdit="True" LinkBrush="Green"
                                               LinkSelected="fCartTst_LinkSelected" LinkDeselected="fCartTst_LinkDeselected" NodeSelected="fCartTst_NodeSelected" NodeDeselected="fCartTst_NodeDeselected"
                                               ShapeBrush="White" MouseLeftButtonDown="fCartTst_MouseLeftButtonDown" MouseMove="fCartTst_MouseMove"/>


                           </ScrollViewer>                         
                                                      
                       </ItemsControl>

Any ideas ?
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: [1] 2 
Send TopicPrint