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


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Changing ContentTemplate in C#
Reply #15 - Feb 24th, 2009 at 9:58am
Print Post  
This modified version of the SaveLoad sample shows how to fill all of the browser's window with the diagram, if that's what you need:

https://mindfusion.eu/_samples/SaveLoad.zip

Set the ScrollViewer's Horizontal/Vertical ScrollBarVisibility properties as you need them. Now it uses the default values - only the vertical scrollbar is visible.

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 #16 - Mar 23rd, 2009 at 9:43am
Print Post  
Hi Stoyan
And back to the content template....
Was it implemented in ver 1.0.2 ?

I'm trying to make the text appear under the Image.
I've done something like :

NewNode.ContentTemplate = CreateNodeDataTemplate();

And the code:
private DataTemplate CreateNodeDataTemplate()
       {
           /*
           <StackPanel Orientation="Vertical">
               <Image ></Image>
               <TextBlock Margin="0,20,0,0"></TextBlock>
           </StackPanel>
           
           
            */


           DataTemplate dt = new DataTemplate();

           StringBuilder sb = new StringBuilder();

           sb.Append("<DataTemplate ");
           sb.Append("xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' ");
           sb.Append("xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'> ");

           sb.Append("<StackPanel Orientation=\"Vertical\">");
           sb.Append("<Image ></Image>");
           sb.Append("<TextBlock Margin=\"0,20,0,0\"></TextBlock>");
           sb.Append("</StackPanel>");
           sb.Append("</DataTemplate>");

           dt = (DataTemplate)XamlReader.Load(sb.ToString());
           return dt;

       }

But then my node dissapear.

I managed to manipulate it a bit by:

                       _dblControlHeight = _dblControlHeight + 20;
                       ((System.Windows.Controls.TextBlock)((((System.Windows.Controls.Grid)(((Canvas)N
ewNode.Content).Children[1])).Children[1]))).Margin = new Thickness(0, 10, 0, 0);


But this is not the right way to do it....

Many thanks for this release, I'll proceed checking it...
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Changing ContentTemplate in C#
Reply #17 - Mar 23rd, 2009 at 12:41pm
Print Post  
Hi Hai,

ContentTemplates are not supported yet. Version 1.0.2 adds TextRectangle property to the Shape class that lets you move the label below the shape outline. Another possibility is to use custom controls hosted in ControlNodes; this is shown in the network chart step in the FCDemo sample here:
https://mindfusion.eu/_beta/DiagramLite102.zip

The beta build we've uploaded today updates exactly this part of the sample, to use hosted controls and the new Serialize/DeserializeControl events that lets you save and load custom control data.

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 #18 - Mar 24th, 2009 at 10:01am
Print Post  
Hi Stoyan

From the 2 alternatives that you have suggested I preffer to use the TextRectangle  property since the other way will force me to duplicate the code… once for ShapeNodes and once for ControlNodes.

But when I read the documentation I see that this property is read only… so how can I use it to, as in the help file, "Specify the label position for this shape."

Here is my code

ShapeNode NewNode = new ShapeNode(wfDiagram);

.......

//Picture node
NewNode.Image = _imgDraggedImage.Source;
                       NewNode.ImageAlign = ImageAlign.TopCenter;

//Align text
StringFormat sf4text = new StringFormat();
sf4text.Alignment = StringAlignment.Far;    //Bottom
sf4text.LineAlignment = StringAlignment.Center;
NewNode.TextFormat = sf4text;


NewNode.Shape.TextRectangle = ???

Can you give me a code sample for this TextRectangle usage that will put the text under the image ?

Many thanks

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


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Changing ContentTemplate in C#
Reply #19 - Mar 24th, 2009 at 10:12am
Print Post  
Hi Hai,

It can be set only through the Shape constructor. Try defining a shape like this:

new Shape(
     Shapes.Rectangle.Outline,
     null,
     new Rect(-30, 100, 160, 50),
     FillRule.Nonzero, "IconShape");

And then assign Shape.FromId("IconShape") to the Shape property of your nodes.

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 #20 - Mar 24th, 2009 at 10:18am
Print Post  
Hi Stoyan

Shapes.Rectangle.Outline does not exist... what to do ?

Using it like:

MindFusion.Diagramming.Silverlight.Shape tmpShape = new MindFusion.Diagramming.Silverlight.Shape(Shapes.Rectangle, null, new Rect(-30, 100, 160, 50), FillRule.Nonzero, "IconShape");

This is where the error is...

And then use it like :
NewNode.Shape = MindFusion.Diagramming.Silverlight.Shape.FromId("IconShape");

Or

NewNode.Shape = tmpShape;

??

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 #21 - Mar 24th, 2009 at 10:24am
Print Post  
ok, replace Shapes.Rectangle.Outline with this:

new ElementTemplate[]
{
     new LineTemplate(0, 0, 100, 0),
     new LineTemplate(100, 0, 100, 100),
     new LineTemplate(100, 100, 0, 100),
     new LineTemplate(0, 100, 0, 0)
}
  
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 #22 - Mar 24th, 2009 at 12:38pm
Print Post  
Hi Stoyan

Sorry for the delay, was out....

But Yup !! it works....

This:
new Rect(-30, 100, 160, 50)

is setting the size of the text box, am I correct ?
and if so, is tere a way to change this size in runtime according to the inserted text ?

Many thanks

Hai

(By the way... we have tried to call you yesterday... but could only speak to your secretary...
Can we try again ? )
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Changing ContentTemplate in C#
Reply #23 - Mar 24th, 2009 at 3:13pm
Print Post  
Hi Hai,

It's the same text rectangle size for all nodes that use this Shape. You could just set the Shape.TextRectangle to a large enough size to fit any label you expect to use in your diagram, or otherwise we can easily make TextRectangle a property of ShapeNode.

Stoyan

p.s. she's doing support work actually, and is the only one with good spoken English around here. Mine is a complete disaster Wink so if you have something only for my ears, better use the send instant message link on the left of this post.
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1 [2] 
Send TopicPrint