2012-10-13 8 views
6

sto cercando di modificare la proprietà MaximumRowsOrColumns della mia WrapGrid in questo modo:Come modificare ItemsPanelTemplate WrapGrid dal codice XAML?

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

E poi sto usando questo codice per modificare il 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> 

Ma io sto ricevendo il error

Informazioni WinRT: Impossibile risolvere TargetName wrapGridItems.

Come dovrei fare riferimento a WrapGrid nella proprietà StoryAnimationUsingKeyFrames Storyboard.TargetName?

risposta

4

Non è possibile accedere agli elementi all'interno dei modelli utilizzando x: Nome. Poiché il modello potrebbe essere istanziato molte volte, l'animazione non sarebbe in grado di dire quale elemento dovrebbe manipolare.

Se è necessario modificare la proprietà di un elemento all'interno del modello che si dovrebbe usare vincolante:

<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 > 

codice C#:

Crea dipendenza Proprietà

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)); 
Problemi correlati