我正在构建一个 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; }
}
最佳答案
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/