tags:

views:

98

answers:

2

I am loading a canvas which contains a lot of children uiElements such as path, line, textblocks. When i look at the width it just shows NaN. When i try to modify the width and height it does not seem to do that. I have also noticed ActualWidth and DesiredWidth do not allow me to set as they are not objects. Please let me know if you have any suggestions. Thanks N

A: 

I am able to height of my canvas without issues. Can you post your code?(though the code should be simple)

Eclipsed4utoo
Thanks for reply.Think of it like this:We got xaml.We load the xaml and get a canvas object.The canvas now has a bunch of children.Just loop thro the children using a foreach loop casting to UIElement.foreach(UIElement uie in cnv.Children){ uie.Width += 200; uie.Height += 200}Here is where the width and height show up as NaN.Add any thing it just continues to be the same.Let me know if you need more info.ThanksN
np
Instead to incrementing as you loop, multiply the number of elements in the collection by 200, and set that to the height, outside of the loop(before or after the loop). That is what I do and it works.
Eclipsed4utoo
Thanks.I tried your suggestion but it does not seem to work, here is the snippet. Please let me know if this is what you meant:public UserControl2() { this.InitializeComponent();//Here is the width of the path this.p1.Width += 200; }
np
in your previous code, you weren't setting the width and height of the canvas. You were setting the width and height of the individual controls within the canvas(which was actually different from your question). Now you are trying to set the width and height of the canvas(assuming that "p1" is the canvas). Can you post more code of what you are trying to actually do? Your question was about resizing a Canvas, yet your first code was resizing the child controls. Now your code is resizing "p1"(don't know what that is). We need more code. Also, post in a new reply so the code is formatted.
Eclipsed4utoo
A: 

Eclipse Thanks. Sorry about not being clear. Actually in my first code i am referring to children of canvas.

`

foreach(UIElement childInCnvs in MyCanvas.Children)

{
    childInCnvs.Width += 200;

}

`

In the second snippet i was trying out in a usercontrol by manually creating a path:

public UserControl2() // a Consturctor
{
    this.InitializeComponent();

    // Here i am trying to set the width of the path

    this.p1.Width += 200;
}

Thanks N

np
so what are you trying to change the size of? the child controls or the canvas itself?
Eclipsed4utoo
@np please update your original question instead of posting an answer.
Foole