あなたのViewModelのプロパティに対してバインドするためにあなたの財産としてIsIndeterminate
プロパティを使用します。この例では私の名前はIsBusy
です。
public partial class Window1 : Window
{
public MyViewModel _viewModel = new MyViewModel();
public Window1()
{
InitializeComponent();
this.DataContext = _viewModel;
}
private void Button_Click(object sender, RoutedEventArgs e)
{
//this would be a command in your ViewModel, making life easy
_viewModel.IsBusy = !_viewModel.IsBusy;
}
}
public class MyViewModel : INotifyPropertyChanged
{
private bool _isBusy = false;
public bool IsBusy
{
get
{
return _isBusy;
}
set
{
_isBusy = value;
PropertyChangedEventHandler handler = PropertyChanged;
if(handler != null)
handler(this, new PropertyChangedEventArgs("IsBusy"));
}
}
#region INotifyPropertyChanged Members
public event PropertyChangedEventHandler PropertyChanged;
#endregion
}
XAMLはButton
のクリックイベントハンドラを使用して、このインスタンスです。あなたのインスタンスでは、アクションをバインドするだけで、ViewModelのコマンドに処理が開始されます。
<Grid>
<ProgressBar Width="100" Height="25" IsIndeterminate="{Binding IsBusy}"></ProgressBar>
<Button VerticalAlignment="Bottom" Click="Button_Click" Width="100" Height="25" Content="On/Off"/>
</Grid>
あなたのViewModelにIsBusy
プロパティを変更する作業と終了作業が続いあなたが後にしているアクティブ/アクティブでない外観を提供し、と停止に不確定な行動を開始します始めると。
私はビジー指標をチェックアウトします。ありがとう – czuroski