首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Silverlight BusyIndicator

Silverlight BusyIndicator
EN

Stack Overflow用户
提问于 2012-01-26 09:22:36
回答 1查看 1.4K关注 0票数 0

有没有办法在BusyIndicator不忙的时候不显示它(IsBusy='false')?在我将silverlight添加到我的UserControl中后,它使用了很大的区域,所以所有其他控件都下移了,BusyIndicator看起来也不再好用了。我需要它在不忙的时候隐藏起来,在忙的时候显示出来。

谢谢你的帮助。

CK

EN

回答 1

Stack Overflow用户

发布于 2012-01-26 14:04:24

我将使用标准的BooleanToVisiblityConverter并将Visibilty绑定到IsBusy属性,如下所示:

代码语言:javascript
复制
    <Grid Height="500" Width="500"  Background="Blue">
    <Grid.Resources>
        <Converters:BoolToVisConverter x:Key="BoolToVis"/>
    </Grid.Resources>
    <Grid.RowDefinitions>
        <RowDefinition Height="*"/>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="Auto"/>
    </Grid.RowDefinitions>
    <StackPanel Width="75">
        <ToggleButton x:Name="BusyButton" Content="Toggle Busy State"/>
        <ToggleButton x:Name="ProgressButton" Content="Toggle ProgressButton State"/>
    </StackPanel>
    <toolkit:BusyIndicator Grid.Row="1" IsBusy="{Binding IsChecked, ElementName=BusyButton}"
                           Visibility="{Binding IsBusy, RelativeSource={RelativeSource Self}}"/>
    <ProgressBar Grid.Row="2" Width="120" Height="10" Margin="4 2" VerticalAlignment="Center" IsIndeterminate="True"
                 Visibility="{Binding IsChecked, ElementName=ProgressButton, Converter={StaticResource BoolToVis}}"/>
</Grid>

在本例中,我提供了BusyIndicator和ProgressBar,因此您可以看到这两种方法的实际效果。

BooleanToVisibilityConverter是非常标准的,并且是这样实现的:

代码语言:javascript
复制
    public class BoolToVisConverter : IValueConverter
{
        #region IValueConverter Members

        public virtual object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value == null) return Visibility.Collapsed;

            return (bool)value == true ? Visibility.Visible : Visibility.Collapsed;
        }

        public virtual object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }

        #endregion
}
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9012870

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档