【问题标题】:Silverlight BusyIndicatorSilverlight 忙碌指示灯
【发布时间】:2012-01-26 01:22:36
【问题描述】:

有没有办法在忙时不显示 BusyIndi​​cator (IsBusy='false')?在我将 silverlight BusyIndi​​cator 添加到我的 UserControl 后,它使用了一个大区域,因此所有其他控件都向下移动,并且 GUI 看起来不再好。我需要它在不忙时隐藏,在忙时显示。

感谢您的帮助。

CK

【问题讨论】:

  • 你能显示更多你想要做什么的代码

标签: silverlight


【解决方案1】:

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

    <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>

我已经提供了 BusyIndi​​cator 以及 ProgressBar 是这个示例,因此您可以看到两者的实际效果。

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

    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
}

【讨论】:

    猜你喜欢
    • 2017-04-08
    • 2012-07-28
    • 2012-01-20
    • 2012-02-04
    • 2011-09-24
    • 2013-04-21
    • 2013-06-25
    • 1970-01-01
    • 2017-05-25
    相关资源
    最近更新 更多