2012-10-13 221 views
6

estoy tratando de modificar la propiedad de mi MaximumRowsOrColumns WrapGrid así:Cómo cambiar ItemsPanelTemplate WrapGrid ¿De código XAML?

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

Y entonces yo estoy usando este código para cambiar el 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> 

Pero yo estoy recibiendo el error

WinRT información: No se puede resolver TargetName wrapGridItems.

¿Cómo debo hacer referencia a WrapGrid en la propiedad ObjectAnimationUsingKeyFrames Storyboard.TargetName?

Respuesta

4

No puede acceder a los elementos dentro de las plantillas usando x: Nombre. Debido a que la plantilla puede ser instanciada muchas veces, la animación no podrá decir qué elemento debe manipular.

Si necesita cambiar la propiedad del elemento dentro de la plantilla que debe utilizar el enlace:

<GridView.ItemsPanel> 
    <ItemsPanelTemplate> 
     <WrapGrid Orientation="Vertical" MaximumRowsOrColumns="{Binding MyMaxRowsOrCollumns}" /> 
    </ItemsPanelTemplate> 
</GridView.ItemsPanel> 
0

Design Code:

<GridView > 

<GridView.ItemsPanel> 
          <ItemsPanelTemplate> 
           <WrapGrid x:Name="wrapGrid" Orientation="Vertical" MaximumRowsOrColumns="{Binding MyMaxRowsOrCollumns}"></WrapGrid> 
          </ItemsPanelTemplate> 
         </GridView.ItemsPanel> 
</GridView > 

código C#:

Crear dependencia Propiedad

public int MyMaxRowsOrCollumns 
    { 
     get { return (int)GetValue(MyMaxRowsOrCollumnsProperty); } 
     set { SetValue(MyMaxRowsOrCollumnsProperty, value); } 
    } 

    // Using a DependencyProperty as the backing store for MyMaxRowsOrCollumns. This enables animation, styling, binding, etc... 
    public static readonly DependencyProperty MyMaxRowsOrCollumnsProperty = 
     DependencyProperty.Register("MyMaxRowsOrCollumns", typeof(int), typeof(DashBord), new PropertyMetadata(2)); 
Cuestiones relacionadas