2

我有一个由 BusyIndi​​cator 包装的 ListBox。ListBox 很重,有时可能需要 4 或 5 秒才能呈现。

我想知道在 ListBox 呈现时使用 BusyIndi​​cator 阻止 UI 的最佳方法是什么?

编辑:对不起,我没有把我的问题说得很清楚......请注意,ListBox 的 ItemsSource 绑定到视图模型中的 ObservabaleCollection。这个集合被快速填充。我猜真正减慢一切的是 UI 渲染,因为 ListBox 包含非常复杂的自定义 ListBoxItems。

ListBox 的ItemsPanel 也是WrapPanel。它不像默认的 VirtualisingStackPanel,所以我猜这可能是 ListBox 性能问题?

4

3 回答 3

1

这基本上是你可以做到的。

XAML 文件

<toolkit:BusyIndicator HorizontalAlignment="Left" VerticalAlignment="Top"
    x:Name="m_BusyIndicator">
    <ListBox Width="200" Height="300" x:Name="m_ListBox"/>
</toolkit:BusyIndicator>

CS文件

public MainPage()
{
    // Required to initialize variables
    InitializeComponent();
    InitializeListBox();
}

private void InitializeListBox()
{
    m_BusyIndicator.IsBusy = true;
    m_ListBox.ItemsSource = null; // Load your data (mayby async) when done call OnListBoxItemsLoaded()
}

private void OnListBoxItemsLoaded()
{
    m_BusyIndicator.IsBusy = false;
}
于 2010-08-12T07:43:38.527 回答
0

如果您不想使用该工具包,可以使用我对这个问题的回答:

WPF - 加载图像以显示页面加载状态

于 2010-08-12T07:48:30.993 回答
0

如果要锁定整个 UI,则需要将整个控件 layoutroot 内容与忙指示符包装起来。

于 2010-08-12T11:47:25.633 回答