FindName (Dynamic controls)
Hi, I have this piece of code
and "prueba" is null, the object is there if you get it by DivContent.Children[0] but the problem is affecting me when I try to call a Storyboard with this DivView as target,
sb.Begin(DivContent) gives just an exception saying "The target name 'DivView' cannot be found in the xaml namscope, and I am afraid that both issues are related.
Btw, I call another storyboard with target declared in xaml and it works perfectly so I think it is something with the controls added dynamically.
cheers!
Code: Select all
DivContent.Children.Clear();
var newview = (UserControl) NoesisGUISystem.LoadXaml(xaml);
newview.Name = "DivView";
DivContent.Children.Add(newview);
var prueba = DivContent.FindName("DivView");
Code: Select all
<Window.Resources>
<Storyboard x:Key="StoryboardLoadView">
<ThicknessAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Margin)" Storyboard.TargetName="DivNewView">
<EasingThicknessKeyFrame KeyTime="0:0:0.2" Value="0">
<EasingThicknessKeyFrame.EasingFunction>
<CircleEase EasingMode="EaseOut"/>
</EasingThicknessKeyFrame.EasingFunction>
</EasingThicknessKeyFrame>
</ThicknessAnimationUsingKeyFrames>
</Storyboard>
Btw, I call another storyboard with target declared in xaml and it works perfectly so I think it is something with the controls added dynamically.
cheers!
-
-
sfernandez
Site Admin
- Posts: 2058
- Joined:
Re: FindName (Dynamic controls)
Hi,
In order to find a dynamically created element you have to first register it in the tree namescope.
For example, if I loaded a XAML and want to add to the root Grid a Button created in code:
I have to register the button in the NameScope:
Since that moment I can do a FindName without problem:
In order to find a dynamically created element you have to first register it in the tree namescope.
For example, if I loaded a XAML and want to add to the root Grid a Button created in code:
Code: Select all
Button button = new Button { Content = "Button" };
grid.Children.Add(button);
Code: Select all
grid.RegisterName("btn", button);
Code: Select all
var btn = grid.FindName("btn");
Who is online
Users browsing this forum: Bing [Bot] and 0 guests