Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Adding comments in diagram (Read 3748 times)
Naganathan
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 22
Joined: Jun 14th, 2010
Adding comments in diagram
Jun 14th, 2010 at 5:26am
Print Post  
Hi,
Can anyone suggest a way to add comment text(editable) in the diagram..

FYI. We have created a custom control derived from ControlNode and and added a TextBlock to that..The TextBlock has MaxWidth and TextWrapping set to 100.And the X,Y position of the comment text is stored in database.Now the problem is the textbox is displayed with the default size of 50,50 automatically and there is noway i could find to display the complete text.
Appreciate your help..

Thanks,
Naganathan NS
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Adding comments in diagram
Reply #1 - Jun 14th, 2010 at 6:44am
Print Post  
Hi,

You can measure text size as shown in the post below, and set your node size based on the result:
http://mindfusion.eu/Forum/YaBB.pl?board=diaglite_disc;action=display;num=127182...

Instead of custom control you could use a ShapeNode and call its ResizeToFitText method. Set the node's Transparent property to true to hide its geometry and leave only the text visible, if that's what you need for the comment text.

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


I love YaBB 1G - SP1!

Posts: 22
Joined: Jun 14th, 2010
Re: Adding comments in diagram
Reply #2 - Jun 14th, 2010 at 8:25am
Print Post  
Hi Stoyan,

Thanks for the quick reply..I tried with ShapeNode and called ResizeToFitText() method after assigning the text. Please have a look at my code.

public ShapeNode1(Diagram diagram,Comment comment) : base(diagram)
{
this.Text = comment.TextComment;
this.TextWrapping = System.Windows.TextWrapping.Wrap;
this.MaxWidth = 100;
ResizeToFitText();
Rect rec = this.GetBounds();
rec.X = comment.XPosition;
rec.Y = comment.YPosition;
this.SetBounds(rec, true);
this.UpdateVisuals();
}

But for some reason,the shapenode is displayed without wrapping with respect to the MaxWidth set to 100..Please tell me whats wrong in this code and it would be helpful if u can share some sample code..

Thanks,
Naganathan NS
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Adding comments in diagram
Reply #3 - Jun 14th, 2010 at 9:12am
Print Post  
Hi,

I'm afraid ResizeToFitText does not honor MaxWidth at this time. The code in that post is a copy of the ResizeToFitText body - try adding a MaxWidth setter to the TextBlock init block and using that code instead of the built-in ResizeToFitText.

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


I love YaBB 1G - SP1!

Posts: 22
Joined: Jun 14th, 2010
Re: Adding comments in diagram
Reply #4 - Jun 14th, 2010 at 9:52am
Print Post  
Hi Stoyan,
I tried the other approach using TextBlock and unfortunately it did not help me to solve the issue..copied the code for your reference...
public ShapeNode1(Diagram diagram,Comment comment) : base(diagram)
{
var textBlock = new TextBlock
{
Text =comment.TextComment,
TextWrapping = TextWrapping.Wrap,
MaxWidth = 100,
Width = double.NaN,
Height = double.NaN,
FontFamily = FontFamily,
FontSize = FontSize
};
textBlock.UpdateLayout();
Size desiredSize = new Size(
textBlock.ActualWidth + TextMargin.Left + TextMargin.Right + StrokeThickness * 2,
textBlock.ActualHeight + TextMargin.Top + TextMargin.Bottom + StrokeThickness * 2);

Rect newBounds = new Rect(new Point(comment.XPosition, comment.YPosition), desiredSize);
this.SetBounds(newBounds, true);
}
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Adding comments in diagram
Reply #5 - Jun 14th, 2010 at 11:24am
Print Post  
Right, setting MaxWidth alone seems to not have any effect. I've managed to measure the size by inserting the TextBlock into a grid as below. I don't know if all parts of the code are necessary, you might experiment removing some of them:

Code
Select All
var node = diagram.Factory.CreateShapeNode(0, 0, 10, 10);
string text = "But for some reason,the shapenode is displayed without wrapping with respect to the MaxWidth set to 100";
var textBlock = new TextBlock
{
	Text = text,
	TextWrapping = TextWrapping.Wrap,
	MaxWidth = 100,
	Width = double.NaN,
	Height = double.NaN,
	FontFamily = node.FontFamily,
	FontSize = node.FontSize
};
var grid = new Grid();
grid.ColumnDefinitions.Add(new ColumnDefinition {MaxWidth = 100});
grid.Children.Add(textBlock);
diagram.DocumentPlane.Children.Add(grid);
grid.UpdateLayout();


//textBlock.Measure(new Size(100, double.PositiveInfinity));
//textBlock.Arrange(new Rect(new Point(), textBlock.DesiredSize));


node.Bounds = new Rect(node.Bounds.X, node.Bounds.Y, textBlock.ActualWidth, textBlock.ActualHeight);
node.TextWrapping = TextWrapping.Wrap;

diagram.DocumentPlane.Children.Remove(grid); 



I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint