2010-08-12 56 views
2

我有一個由BusyIndi​​cator包裝的ListBox。 ListBox很沉重,有時可能需要4或5秒才能渲染。Silverlight - 當ListBox使用BusyIndi​​cator呈現時屏蔽屏幕

我不知道什麼是在ListBox呈現時使用BusyIndi​​cator阻止UI的最佳方式?

編輯:對不起,我沒有讓我的問題很清楚...請注意,ListBox的ItemsSource綁定到視圖模型中的ObservabaleCollection。這個收集是快速填充。我猜想,真正拖慢所有事情的是UI渲染,因爲ListBox包含了非常複雜的自定義ListBoxItems。

另外ListBox的ItemsPanel是一個WrapPanel。它不像默認的VirtualisingStackPanel,所以我猜這可能是一個ListBox性能問題?

回答

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; 
} 
+0

我不認爲它是減慢速度的ItemsSource。請參考我調整後的問題。謝謝。 :) – 2010-08-12 23:45:30

0

如果你不想使用該工具包可以用我這個問題的答案:

WPF - Loading image to show page loading status

+0

感謝這一點,但在我的情況下,我不得不使用這個BusyIndi​​cator。 :( – 2010-08-12 23:40:40

0

如果你想鎖定整個用戶界面,那麼你需要包裝整個控件layoutroot nt與忙指標。

+0

我有BusyIndi​​cator作爲我的根元素。 – 2010-08-12 23:40:16

相關問題