Skip to main content

Microsoft Silverlight

Answered Question About FindName (Beta2)RSS Feed

(0)

Oliver.Dong
Oliver.Dong

Member

Member

1 points

8 Posts

About FindName (Beta2)

string  xmlRoot =" <TextBlock Name='myTxt' xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation'  Canvas.Left='190' Canvas.Top='140'  FontSize='12' Foreground='Black' Text='fasdfsadfasdfasdfasfasdsdfasdfsadfsdafsdfasdfsad1111'></TextBlock> ";

UIElement documentRoot = (UIElement)XamlReader.Load(xmlRoot );
 _MyCanvas.Children.Add(documentRoot);

//find the control

TextBlock tb = (TextBlock)_MyCanvas.FindName('myTxt' );

now , tb is null,why?

 thanks for you help;

johnnystock
johnnystock

Contributor

Contributor

2295 points

362 Posts

Silverlight MVP

Re: About FindName (Beta2)

Instead of "Name" in your xaml, use "x:Name".

John Stockton
Microsoft Silverlight MVP and RIA Developer at Ascentium
Co-Author of Silverlight 2 in Action

Oliver.Dong
Oliver.Dong

Member

Member

1 points

8 Posts

Answered Question

Re: About FindName (Beta2)

 

Thanks ,johnny。

I used this method ,thanks to the author

Panel root = (Panel) XamlReader.Load(...);

UIElement realRoot = root.Children[0]; root.Children.Remove(realRoot);

 then add realRoot to your tree. This will not create a new namescope.

 

SteveWong
SteveWong

Contributor

Contributor

6343 points

1,281 Posts

Re: Re: About FindName (Beta2)

By the way you can call directly

myTxt.Text = "something here" rather than using findname

Regards,
SteveWong (HongKong)
Please mark post as answer if they help you

Client App Dev
  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities