我正在使用带有WCF Ria服务的Silverlight 5。为了快速开发,我编写了一个基于提供程序的系统来填充ComboBoxes。当我为一个组合设置提供程序并将EditValue绑定到ViewModel时,一切都很完美。
<Controls:BLComboBoxEdit2 x:Name="cbeDepartmentId"
EditValue="{Binding Path=Selected.DepartmentId, Mode=TwoWay"
ComboDataProvider="{Binding Path=DepartmentComboDataProvider}" />
但是为了在combo等待提供者加载数据时通知用户我需要一个BusyIndicator。我无法弄清楚如何在继承的控件中显示BusyIndicator(我们可以通过重写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>
当我运行上面的代码时,组合工作正常但忙碌指示器未显示(正如预期的那样,忙碌指示器成为组合的内容,如果我弹出组合[在加载过程中]我可以看到BusyIndicator :)但是在第一次加载后,它会因内容发生变化而消失。
有办法做到这一点吗?现在我试图在后面的代码中设置内容(在IsBusy更改后我想将内容设置为BusyIndicator或默认保留),但没有运气。
非常感谢任何帮助。
答案 0 :(得分:1)
尝试将两个控件意味着组合框和busyindicator放在同一个地方,就像在Grid的同一列上一样,并在异步调用之前使IsBusy = true(两者具有相同的高度和重量)并更改它在已完成的活动上为假
将comboBox放在BusyIndicator中作为内容
<toolkit:BusyIndicator x:Name="busyIndicator" Style="{StaticResource AjaxBusyIndicator}" IsBusy="{Binding Path=ComboDataProvider.IsWorking}">
<ComboBox/>
</toolkit:BusyIndicator>