0

WPFのProgressBarVisibility要素にバインドするにはどうすればよいですか?折りたたみ、表示、非表示の3つのオプションを持つ列挙型を使用するため、文字列プロパティにバインドできません。ProgressBarのバインドされた可視性のための理解可能なコードを示してください。前もって感謝します。

4

1 に答える 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 に答える