Silverlight - 使用BusyIndi​​cator在ListBox渲染时阻止屏幕

时间:2010-08-12 06:38:03

标签: silverlight silverlight-3.0 listbox busyindicator

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

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

编辑:对不起我没有明白我的问题...请注意ListBox的ItemsSource绑定到viewmodel中的ObservabaleCollection。这个集合很快填充。我认为真正减慢一切的是UI渲染,因为ListBox包含非常复杂的自定义ListBoxItem。

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

3 个答案:

答案 0 :(得分: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;
}

答案 1 :(得分:0)

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

WPF - Loading image to show page loading status

答案 2 :(得分:0)

如果要锁定整个UI,则需要使用忙碌指示器包装整个控件layoutroot内容。

相关问题