有没有办法在BusyIndicator不忙的时候不显示它(IsBusy='false')?在我将silverlight添加到我的UserControl中后,它使用了很大的区域,所以所有其他控件都下移了,BusyIndicator看起来也不再好用了。我需要它在不忙的时候隐藏起来,在忙的时候显示出来。
谢谢你的帮助。
CK
发布于 2012-01-26 14:04:24
我将使用标准的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>在本例中,我提供了BusyIndicator和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
}https://stackoverflow.com/questions/9012870
复制相似问题