0
如何綁定到WPF的ProgressBar Visibility元素?我無法將它綁定到字符串屬性,因爲它需要一個帶有三個選項的枚舉:Collapsed,Visible和Hidden。 請爲ProgressBar的綁定可見性顯示可理解的代碼。提前致謝。如何綁定到WPF ProgressBar的Visibility元素?
如何綁定到WPF的ProgressBar Visibility元素?我無法將它綁定到字符串屬性,因爲它需要一個帶有三個選項的枚舉:Collapsed,Visible和Hidden。 請爲ProgressBar的綁定可見性顯示可理解的代碼。提前致謝。如何綁定到WPF ProgressBar的Visibility元素?
<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");
}
}
}
感謝您的答覆:)ü可以給我一個綁定的值碼? – user27 2012-07-19 08:54:26
當然,我會編輯答案。 – 2012-07-19 09:17:39