Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change ItemsPanelTemplate WrapGrid From XAML code?

Tags:

c#

windows-8

xaml

I'm trying to modify the MaximumRowsOrColumns property of my WrapGrid like this:

<GridView.ItemsPanel>
    <ItemsPanelTemplate>
        <WrapGrid x:Name="wrapGridItems" Orientation="Vertical" MaximumRowsOrColumns="1" />
    </ItemsPanelTemplate>
</GridView.ItemsPanel>

And then I'm using this code to change the WrapGrid:

<VisualState x:Name="Snapped">
    <Storyboard>
        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="wrapGridItems" Storyboard.TargetProperty="MaximumRowsOrColumns">
            <DiscreteObjectKeyFrame KeyTime="0" Value="-1"/>
        </ObjectAnimationUsingKeyFrames>
            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="headerText" Storyboard.TargetProperty="Text">
            <DiscreteObjectKeyFrame KeyTime="0" Value="Pins"/>
        </ObjectAnimationUsingKeyFrames>
    </Storyboard>
</VisualState>

But I'm getting the error

WinRT information: Cannot resolve TargetName wrapGridItems.

How should I refer to the WrapGrid in the ObjectAnimationUsingKeyFrames Storyboard.TargetName property?

like image 672
MatthewSot Avatar asked Oct 13 '12 02:10

MatthewSot


1 Answers

You can not access elements inside templates using x:Name. Since template could be instantiated many times animation wouldn't be able to tell which element it should manipulate.

If you need to change property of element inside the template you should use binding:

<GridView.ItemsPanel>
    <ItemsPanelTemplate>
        <WrapGrid Orientation="Vertical" MaximumRowsOrColumns="{Binding MyMaxRowsOrCollumns}" />
    </ItemsPanelTemplate>
</GridView.ItemsPanel>
like image 72
Denis Avatar answered Nov 01 '22 18:11

Denis