如何绑定到 WPF 的 ProgressBar Visibility 元素?我无法将它绑定到字符串属性,因为它需要一个具有三个选项的枚举:折叠、可见和隐藏。请为 ProgressBar 的绑定可见性显示可理解的代码。提前致谢。
问问题
3640 次
1 回答
6
<Grid Width="150" Margin="30,0" Visibility="{Binding ProgressBarVisibility}">
<ProgressBar Width="150" Height="Auto" HorizontalAlignment="Stretch" Foreground="#FF01D328"
Minimum="-3" Maximum="100" Value="{Binding DownloadPercentage, Mode=OneWay}" />
<TextBlock Text="Downloading" HorizontalAlignment="Center" />
</Grid>
在视图模型中:
public Visibility ProgressBarVisibility
{
get
{
return (DownloadingPdf && DownloadPercentage < 100) ? Visibility.Visible : Visibility.Collapsed;
}
}
private int mDownloadPercentage;
public int DownloadPercentage
{
get { return mDownloadPercentage; }
set
{
if (mDownloadPercentage==value)
{
return;
}
else
{
mDownloadPercentage = Math.Min(Math.Abs(value), 100);
OnPropertyChanged("DownloadPercentage");
OnPropertyChanged("DownloadProgressBarVisibility");
}
}
}
于 2012-07-19T07:17:54.183 回答