3

リスト ボックスにアイテムが追加されたときに、初期アニメーションを追加しようとしています。このために、itemcontainerstyle 内のブレンドによって生成された Layoutstates を使用しています。

<VisualStateGroup x:Name="LayoutStates">
    <VisualStateGroup.Transitions>
        <VisualTransition GeneratedDuration="0:0:0.2"/>
    </VisualStateGroup.Transitions>
    <VisualState x:Name="AfterLoaded"/>
    <VisualState x:Name="BeforeLoaded">
        <Storyboard>
            <DoubleAnimation Duration="0" To="35" Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.TranslateY)" Storyboard.TargetName="grid" d:IsOptimized="True"/>
            <DoubleAnimation Duration="0" To="0" Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="grid" d:IsOptimized="True"/>
        </Storyboard>
    </VisualState>
    <VisualState x:Name="BeforeUnloaded">
        <Storyboard>
            <DoubleAnimation Duration="0" To="0.85" Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.ScaleX)" Storyboard.TargetName="grid" d:IsOptimized="True"/>
            <DoubleAnimation Duration="0" To="0.85" Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.ScaleY)" Storyboard.TargetName="grid" d:IsOptimized="True"/>
            <DoubleAnimation Duration="0" To="0" Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="grid" d:IsOptimized="True"/>
        </Storyboard>
    </VisualState>
</VisualStateGroup>

私のリストボックスは次のようになります。

<ListBox Grid.Row="1" ItemsSource="{Binding Days}" x:Name="Days"
                    HorizontalAlignment="Stretch"
                    SelectedItem="{Binding CurrentDay, Mode=TwoWay}" 
                    ItemTemplate="{StaticResource TimeRecordByDayItemTemplate}" 
                    ItemsPanel="{StaticResource ByMonthDaysItemsPanelTemplate}"
                    ScrollViewer.HorizontalScrollBarVisibility="Disabled" 
                    ItemContainerStyle="{StaticResource DayListBoxItemStyle}" />

channel9 のチュートリアルを順を追って実行しただけなのに、アニメーションが表示されません。

これは私の状態マネージャーの最初の問題です。データトリガーの問題も発生しています。特定の条件が満たされたときに状態になる必要があります。機能するものと機能しないものがありますが、バインディングはすべて正しいです! また、すべてのアニメーションは Expression Blend プレビューで機能します。

私は問題を理解することはできません.Silverlightとアニメーションが自分の環境で動作していない最も単純なサンプルからコピーされたので、これが頻繁にありまし.

助けてくれてありがとう!

4

1 に答える 1

1

すべてがロードされたら、アイテムを 1 つずつ追加する必要があるようです。簡単な解決策は、ビューモデルでこれになるようです:

public class MyViewModel
{
  private string[] _items;
  private ObservableCollection<string> _itemCollection;

  public MyViewModel()
  {
     // meets requirement of loading items in constructor
     _items =  { "Johnny", "Thommy", "Jay", "Wommy" };
  }

  public ObservableCollection<string> Items
  {
    get
    {
        if (_itemCollection == null)
        {
           _itemCollection = new ObservableCollection<string>();
           Dispatcher.Invoke(() => LoadItems());
        }
        return _itemCollection;
    }
  }

  private void LoadItems()
  {
    foreach (var item in _items)
    {
      ItemCollection.Add(item);
    }
  }
}

基本的に、ListBox がバインディングをセットアップするとき、コレクションへのアイテムの追加をキューに入れます。これにより、アイテムが適切なタイミングでロードされ、アニメーションがトリガーされるようになります。

于 2011-09-16T18:22:22.407 に答える