c# - ExpanderView 的性能不利于扩展(XAML + UWP)

标签 c# wpf xaml expander uwp

我正在构建一个 UWP 应用程序,它使用 WPF ExpanderView 的移植版本 ( ExpanderRT on Codeplex ),我使用 ListBox 来显示多个 ExpanderViews,具体取决于我的 ViewModel 中的数据。我在扩展包含多个项目的 ExpanderView 时遇到了性能问题。正如您在 GIF 中看到的那样,第一个父项展开非常缓慢,需要一些时间才能显示所有子项。如果 parent 没有那么多 child ,动画会非常流畅。

有没有人使用过这个控件,可以帮助我加快扩展速度?

这是我的 XAML 代码:

        <Grid>
    <ListBox Name="listbox">
        <ListBox.ItemContainerStyle>
            <Style TargetType="ListBoxItem">
                <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
            </Style>
        </ListBox.ItemContainerStyle>
        <ListBox.ItemsPanel>
            <ItemsPanelTemplate>
                <StackPanel/>
            </ItemsPanelTemplate>
        </ListBox.ItemsPanel>
        <ListBox.ItemTemplate>
            <DataTemplate x:DataType="models:Parent">
                <controls:ExpanderControl
                    ItemsSource="{x:Bind Childs}"
                    HeaderTemplate="{StaticResource CustomHeaderTemplate}" 
                    ExpanderTemplate="{StaticResource CustomExpanderTemplate}"
                    ItemTemplate="{StaticResource CustomItemTemplate}"
                    NonExpandableHeaderTemplate="{StaticResource CustomNonExpandableHeaderTemplate}" />
            </DataTemplate>
        </ListBox.ItemTemplate>
    </ListBox>
</Grid>

此代码来自模型

public class Category
{
    public string Name{ get; set; }
    public List<Subcategory> Childs{ get; set; }
}

Slow expanding

最佳答案

Justin XL 为我指明了正确的方向! 此行为是由 ExpanderView 的动画引起的。

ExpanderControl.cs 类中有这些属性来控制折叠和展开过程的动画。

    private const int KeyTimeStep = 35;
    private const int InitialKeyTime = 225;
    private const int FinalKeyTime = 250;

减小 KeyTimeStep 的值会导致更快的展开和折叠动画。

谢谢!

关于c# - ExpanderView 的性能不利于扩展(XAML + UWP),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32500490/

相关文章:

c# - 使用查询字符串 MVC 将数组传递给 View

泛型的 C# 转换错误

wpf - DataGrid内的Combobox,隐藏Combobox上的选定项

c# - 以编程方式更改 defaultproxy 而不是使用 app.config

c# - 无需 INotifyPropertyChanged 即可双向数据绑定(bind)到 POCO

c# - 为什么这个附加属性没有更新?

wpf - 在运行时更改 ListView 标题列高亮背景颜色

c# - 从按日期范围查看的数据库数据导出到 csv asp.net mvc3

c# - 如何为此聊天应用程序使用 Ajax

c# - 鼠标事件在 WPF 中如何工作?