【问题标题】:How to display BusyIndicator in a ComboBox如何在组合框中显示 BusyIndi​​cator
【发布时间】:2012-07-10 19:04:45
【问题描述】:

我将 Silverlight 5 与 WCF Ria 服务一起使用。为了快速开发,我编写了一个基于提供程序的系统来填充组合框。当我为组合设置提供程序并将 EditValue 绑定到 ViewModel 时,一切正常。

<Controls:BLComboBoxEdit2 x:Name="cbeDepartmentId" 
  EditValue="{Binding Path=Selected.DepartmentId, Mode=TwoWay" 
  ComboDataProvider="{Binding Path=DepartmentComboDataProvider}" />

但是为了在组合等待提供者加载数据时通知用户,我需要一个 BusyIndi​​cator。我不知道如何在继承的控件中显示 BusyIndi​​cator(我们可以通过覆盖 OnPaint 事件等在 WinForm 时代做到这一点)所以我创建了一个 UserControl,xaml 是这样的(我们使用的是 DevExpress ComboBoxEdit),

<UserControl ...>

<UserControl.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="../Assets/Styles.xaml" />
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
</UserControl.Resources>

<Grid>
    <dxe:ComboBoxEdit x:Name="combo" />
    <toolkit:BusyIndicator x:Name="busyIndicator" Style="{StaticResource AjaxBusyIndicator}"
            IsBusy="{Binding Path=ComboDataProvider.IsWorking}">
    </toolkit:BusyIndicator>
</Grid>

它看起来像这样,

在某些情况下(对于网格列等),我们需要一个 ComboBoxEdit 派生控件,而不是 UserControl。所以我开始修改代码,但我卡住了。我不知道如何添加子控件(或覆盖控件?)以在控件忙碌时显示。

<dxe:ComboBoxEdit ...>

<dxe:ComboBoxEdit.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="../Assets/Styles.xaml" />
        </ResourceDictionary.MergedDictionaries>
        <Common:PublicStrings x:Key="ResourceStrings" />
    </ResourceDictionary>
</dxe:ComboBoxEdit.Resources>

<Grid>
    <toolkit:BusyIndicator x:Name="busyIndicator" Style="{StaticResource AjaxBusyIndicator}"
            IsBusy="{Binding Path=ComboDataProvider.IsWorking}" />
</Grid>

当我运行上述代码时,组合工作正常,但未显示忙碌指示符(正如此代码所预期的那样,忙碌指示符成为组合的内容,如果我弹出组合[正在加载时]我可以看到 BusyIndi​​cator :) 但在第一次加载后,它会因为内容发生变化而消失)。

有没有办法做到这一点?现在我正在尝试在代码后面设置内容(在 IsBusy 更改后,我想将内容设置为 BusyIndi​​cator 或保留为默认值),但没有运气。

任何帮助将不胜感激。

【问题讨论】:

    标签: silverlight busyindicator


    【解决方案1】:
    1. 尝试在异步调用之前将这两个控件表示组合框和忙指示符放在同一个位置,例如放在 Grid 的同一列上,并使 IsBusy= true(两者具有相同的高度和重量)并更改它在完成事件时为 false

    2. 将组合框作为内容放入 BusyIndi​​cator 中

       <toolkit:BusyIndicator x:Name="busyIndicator" Style="{StaticResource AjaxBusyIndicator}" IsBusy="{Binding Path=ComboDataProvider.IsWorking}">
         <ComboBox/>
      </toolkit:BusyIndicator>
      

    【讨论】:

    • 感谢您的回答。实际上我正在使用这种方法(您可能在上面的代码中看到,combo 和 busyindicator 在同一网格行中),我将其转换为用户控件(BLComboBoxEdit)避免为每个组合用法编写 BusyIndi​​cator,但是这样控件的类型是 UserControl。我需要 ComboBoxEdit 派生控件才能在某些情况下使用。从 ComboBoxEdit 派生时,我意识到我不知道将 BusyIndi​​cator xaml 放在哪里。如果我直接编写它它变成了内容。我需要将 BusyIndi​​cator 显示为组合上的叠加层。顺便说一下,这个问题的优先级已经改变,现在不是必须的 :)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-06-25
    • 2011-06-01
    • 2013-04-19
    • 2011-10-06
    • 2012-11-11
    • 2015-03-21
    • 2012-04-30
    相关资源
    最近更新 更多