none
Storyboard.Clone() - No applicable name scope exists to resolve the name '...'

    Question

  • Hi all!

    I'm trying to make some simple engine with runtime model creation & dynamic animation bindings.
    To do this i have to make some clones of storyboards that lives in resourcedictionary.

    But there is something wrong:  if i create storyboard clone and call .Begin() for it,  then InvalidOparationExeption
    "No applicable name scope exists to resolve the name 'submodel1'." occurs.

    Here is simple expample:   I have window with viewport.

            private void Window_Loaded(object sender, RoutedEventArgs e)  
            {  
                Model3DGroup model = (Model3DGroup)FindResource("StolbBox");  
                ModelVisual3D modelVisual = new ModelVisual3D();              
                modelVisual.Content = model;  
     
                viewPort.Children.Add(modelVisual);  
                viewPort.RegisterName("submodel1", model.Children[1]);  
                  
                Storyboard sb = (Storyboard)viewPort.FindResource("AnimON");  
     
                sb = sb.Clone();  // <-- something lost here :(  
     
                foreach (Timeline anim in sb.Children)  
                {  
                    Storyboard.SetTargetName(anim, "submodel1");  
                }  
                sb.Begin();  // <-- "No applicable name scope exists to resolve the name 'submodel1'."
     
            } 

    SetTargetName called in foreach, because in real app i bind different animations to different models.
    Just delete "sb = sb.Clone();" line and exeption will go away. But... i need multiple storyboard instances for my app :(


    Model looks like this:

            <Model3DGroup x:Key="StolbBox">  
                    <Model3DGroup.Transform> 
                        <Transform3DGroup> 
                            <TranslateTransform3D OffsetX="0" OffsetY="0" OffsetZ="0"/>  
                            <ScaleTransform3D ScaleX="1" ScaleY="1" ScaleZ="1"/>  
                            <RotateTransform3D d:EulerAngles="0,0,0"/>  
                            <TranslateTransform3D OffsetX="0" OffsetY="0" OffsetZ="0"/>  
                            <TranslateTransform3D OffsetX="0" OffsetY="0" OffsetZ="0"/>  
                        </Transform3DGroup> 
                    </Model3DGroup.Transform> 
                  
                  
                  
                    <Model3DGroup> 
                        <Model3DGroup.Transform> 
                            <Transform3DGroup> 
                                <TranslateTransform3D OffsetX="0" OffsetY="0" OffsetZ="0"/>  
                                <ScaleTransform3D ScaleX="1" ScaleY="1" ScaleZ="1"/>  
                                <RotateTransform3D d:EulerAngles="0,0,0"/>  
                                <TranslateTransform3D OffsetX="0" OffsetY="0" OffsetZ="0"/>  
                                <TranslateTransform3D OffsetX="0" OffsetY="0" OffsetZ="0"/>  
                            </Transform3DGroup> 
                        </Model3DGroup.Transform>              
                         <StaticResource ResourceKey="PolSborka"/>  
                    </Model3DGroup> 
                 
    <!-- ... huge skip ..... -->

         </Model3DGroup>

    I've already tried to fix it with  something like: "NameScope.SetNameScope(sb, NameScope.GetNameScope(CurrentViewport));"  but it seems to be wrong...

    ---
    Uploaded small test project here: http://clip2net.com/page/m9923/601660   (zip ~30kb)
    There is also demo of another one issue with Storyboard.SetTarget() and immutable exeption. I wrote another big post about it, but at the end browser crashed and ruined all that i typed so long.. that's not my day :))  

    Ok, i hope somebody knows the answer.
    Thanks, Igor.

    ps: autosave-draft feature would be good for this forum ;)
    • Edited by Antares19 Monday, February 09, 2009 7:08 AM test project uploaded
    Monday, February 09, 2009 5:15 AM

Answers

  • After spending a lot of time in goggling and testing i've found correct way to do this.
    As i thought there is small simple thing i've missed here. 

    viewPort.Resources.Add("unique_iq",sb);

    That's should be right after sb.Clone(); .

    That will work for me now.

    Anyway in my app, i'm creating a lots of model and storyboard clones. I think that registring+unregistring every clone in resources and namescopse will add noticeable performance overhead.  Direct passing models to storyboards by SetTarget() seems to be a better way to do it.  But there is "immutable" bug i've mentioned before. I think i'll post about it later in other new tread.

    ps: in demo project there is some little copy-paste bug. last line should be sb.Begin(), as in example i've posted above.
    pps: if someone interested, there is immutable bug demo in this demo project.

    • Marked as answer by Antares19 Tuesday, February 10, 2009 2:46 AM
    Tuesday, February 10, 2009 2:45 AM