2012-10-13 14 views
6

Próbuję zmodyfikować właściwość MaximumRowsOrColumns mojego WrapGrid takiego:Jak zmienić ItemsPanelTemplate WrapGrid Od kodu XAML?

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

A potem używam tego kodu, aby zmienić 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> 

Ale jestem uzyskiwanie błąd

Informacje o WinRT: Nie można rozwiązać obiektu docelowego wrapGridItems.

Jak powinienem odnieść się do WrapGrid w Object Strike ObjectAnimationUsingKeyFrames Storyboard.TargetName?

Odpowiedz

4

Nie można uzyskać dostępu do elementów wewnątrz szablonów za pomocą x: Nazwa. Ponieważ szablon mógł być tworzony wielokrotnie, animacja nie byłaby w stanie powiedzieć, który element powinien nim manipulować.

Jeśli trzeba zmienić właściwość elementu wewnątrz szablonu należy użyć Oprawa:

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

kod projektu:

<GridView > 

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

kod C#:

Tworzenie dependancy nieruchomości

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)); 
Powiązane problemy