locked
Dynamically Building Storyboards at RunTime

    Question

  • Hi there,

    I have a gridview being filled with buttons via a control template, what I'm trying to do is add a storyboard to some of them and change some properties of the storyboard so that it targets the necessary control.

    I'm having trouble accessing the transformgroup from the control template. I have tried both the datatemplate / grid transformations of the contenttemplate part and also the button rendertransform value, both seem to get rendered elsewhere as the buttons content shows null.

    I'd like to access it so that I can name the dynamically generated transforms to have the correct names.

    Or is there another way I can access a specific transform for an animation without having to worry about naming?

    Nick.


    Somewhere out there...

    Saturday, April 05, 2014 3:56 PM

Answers

  • Hi Firkinfedup,

    Sounds like you meet a issue of finding control from the template, its a quite common question and I would like suggest you go through this blog: http://blog.jerrynixon.com/2012/09/how-to-access-named-control-inside-xaml.html

    By finding the correct control, you can apply your second reply solution and should be ok.

    Hope helps.

    --James


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Tuesday, April 08, 2014 5:26 AM
    Moderator

All replies

  • I can get my code working one a standalone button, just not one created from a content template, for example,

                <Button x:Name="Pop" localui:SynaesthesiaFlicker.Mode="Enabled:Start" Width="256" Height="256" Content="Test">
                    <Button.Background>
                        <SolidColorBrush Color="Red" />
                    </Button.Background>
                    <Button.RenderTransform>
                        <TransformGroup>
                            <RotateTransform x:Name="Pop_RotateTransform" 
                                                     CenterX="128" 
                                                     CenterY="128" 
                                                     Angle="0" />
                        </TransformGroup>
                    </Button.RenderTransform>
                </Button>

    What happens with this is once the button is rendered and the SynaesthesiaFlicker.Mode property is set, it adds a storyboard to the buttons resources, when I come to begin the storyboard I have to set the target via its object reference as the storyboard targeting can't find the render transform 'Pop_RotateTransform".

    I'm sure that's something to do with the visual tree being modified dynamically, and possibly the reason I can't get it to work with the content template as I can't find the render transform for the button.

    I thought maybe if I can dynamically set the name within the content template that would help, then I should be able to locate it when required.

    So I guess that's but current question.

    "Is it possible to give content template controls specific and unique names that can be found in the visual tree via FindName at runtime?"

    Something like ParentName_ChildName would be ideal, and which is what I wanted to do originally but with less bodges in.

    Nick.


    Somewhere out there...

    Saturday, April 05, 2014 4:40 PM
  • I have something working now but it's outside of the content template, for example,

                                <Button x:Name="BrowseArtists" localui:SynaesthesiaFlicker.Mode="Enabled:Start" Width="256" Height="256" Click="BrowseArtists_Click" Style="{StaticResource ArtistsBrowseButtonStyle}" Content="Artists" >
                                    <Button.RenderTransform>
                                        <TransformGroup>
                                            <RotateTransform x:Name="BrowseArtists_RotateTransform" 
                                                     CenterX="128" 
                                                     CenterY="128" 
                                                     Angle="0" />
                                        </TransformGroup>
                                    </Button.RenderTransform>
                                </Button>

    It's not as nice as I want really as it means I'll have to declare the transformgroup for every control using this.  Any ideas on how to move this back into the content template as mentioned above?


    Somewhere out there...

    Saturday, April 05, 2014 5:08 PM
  • Hi Firkinfedup,

    Sounds like you meet a issue of finding control from the template, its a quite common question and I would like suggest you go through this blog: http://blog.jerrynixon.com/2012/09/how-to-access-named-control-inside-xaml.html

    By finding the correct control, you can apply your second reply solution and should be ok.

    Hope helps.

    --James


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Tuesday, April 08, 2014 5:26 AM
    Moderator
  • Thanks James, i'll try this out as soon as I can, it probably won't be for a while yet but your answer seems sound enough so I've marked it as correct.

    Somewhere out there...

    Thursday, April 17, 2014 10:01 AM