【问题标题】:Silverlight - Block the screen while the ListBox is rendering using BusyIndicatorSilverlight - 在 ListBox 使用 BusyIndi​​cator 呈现时阻止屏幕
【发布时间】:2011-03-28 18:34:55
【问题描述】:

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

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

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

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

【问题讨论】:

    标签: silverlight silverlight-3.0 listbox busyindicator


    【解决方案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;
    }
    

    【讨论】:

    • 我不认为是 ItemsSource 减慢了速度。请参考我调整后的问题。谢谢。 :)
    【解决方案2】:

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

    WPF - Loading image to show page loading status

    【讨论】:

    • 谢谢你,但在我的情况下,我必须使用这个 BusyIndi​​cator。 :(
    【解决方案3】:

    如果你想锁定整个 UI,那么你需要将整个控件 layoutroot 内容用忙指示符包裹起来。

    【讨论】:

    • 我将 BusyIndi​​cator 作为我的根元素。
    猜你喜欢
    • 2011-03-27
    • 2011-08-17
    • 2012-04-11
    • 2012-09-05
    • 2011-03-15
    • 2011-03-01
    • 2013-06-17
    • 2013-09-29
    • 2012-11-11
    相关资源
    最近更新 更多