How to remove ListView's add item animation?

后端 未结 7 2225
攒了一身酷
攒了一身酷 2021-02-14 06:26

I have a ListView and I edited its ItemContainerStyle to modify some style but I don\'t know how to remove that annoying animation when you add an item

相关标签:
7条回答
  • 2021-02-14 06:39

    Thanks to Damir's answer, this is how I did it. Just add this in your App.xaml

    <Application...>
        <Application.Resources>
            <ResourceDictionary>
                ...
                <Style TargetType="ListView">
                    <Setter Property="ItemContainerTransitions">
                        <Setter.Value>
                            <TransitionCollection/>
                        </Setter.Value>
                    </Setter>
                </Style>
            </ResourceDictionary>
        </Application.Resources>
    </Application>
    
    0 讨论(0)
  • 2021-02-14 06:44

    These animations are called transitions and they are part of ListViewStyle. To change it right click on ListView control in the designer and select Edit Template > Edit a Copy.... This will add the built-in style to your XAML.

    The following part of the style is of interest to you:

    <Setter Property="ItemContainerTransitions">
        <Setter.Value>
            <TransitionCollection>
                <AddDeleteThemeTransition/>
                <ContentThemeTransition/>
                <ReorderThemeTransition/>
                <EntranceThemeTransition IsStaggeringEnabled="False"/>
            </TransitionCollection>
        </Setter.Value>
    </Setter>
    

    I'm not sure which animation exactly you dislike but try removing AddDeleteThemeTransition and/or EntranceThemeTransition from TransitionCollection. It should do the trick.

    Don't forget to make sure the modified style is applied to the desired ListView.

    0 讨论(0)
  • 2021-02-14 06:46

    It might be in the default ItemsPanel.

    You could try something like this:

    <ListView.ItemsPanel>
        <ItemsPanelTemplate>
            <VirtualizingStackPanel>
                <VirtualizingStackPanel.ChildrenTransitions>
                    <TransitionCollection/>
                </VirtualizingStackPanel.ChildrenTransitions>
            </VirtualizingStackPanel>
        </ItemsPanelTemplate>
    </ListView.ItemsPanel>
    

    Why though do you want to go against the fluid part of the Fast and Fluid thing of the design language? Are you trying to implement something more bland than the templates or are you planning on adding your own transitions?

    0 讨论(0)
  • 2021-02-14 06:47

    In UWP, I created the following code to remove the animation:

    // Remove Add/Delete animations
    TransitionCollection tc = _listView.ItemContainerTransitions;
    for (int i = tc.Count - 1; i >= 0; i--) if (tc[i] is AddDeleteThemeTransition) tc.RemoveAt(i);
    
    0 讨论(0)
  • 2021-02-14 06:48

    This will work --

    listView.ItemContainerTransitions = null;
    

    You have to assign a new reference (or null) to the ItemContainerTransitions property. Changing the values in the collection already referenced by this property will not work.

    This will NOT work --

    listView.ItemContainerTransitions.Clear();
    
    0 讨论(0)
  • 2021-02-14 06:54

    As one of the comments mentioned, simply adding this did the trick for me:

    <ListView.ItemContainerTransitions> 
        <TransitionCollection/> 
    </ListView.ItemContainerTransitions>
    

    No need for all the other code.

    0 讨论(0)
提交回复
热议问题