Skip to main content
Home Forums Silverlight Programming Programming with .NET - General About FindName (Beta2)
3 replies. Latest Post by SteveWong on June 19, 2008.
(0)
Oliver.Dong
Member
1 points
8 Posts
06-19-2008 8:00 AM |
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
Contributor
2295 points
362 Posts
06-19-2008 8:39 AM |
Instead of "Name" in your xaml, use "x:Name".
06-19-2008 8:43 AM |
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
6343 points
1,281 Posts
06-19-2008 9:10 AM |
By the way you can call directly
myTxt.Text = "something here" rather than using findname