Reputation: 85
i have one function for controlling visibility of circular progressbar in view.
public void ShowProgressBarControl()
{
CircleProgressBar.Visibility = Visibility.Visible;
CircleProgressBar.Opacity = 1;
}
I want to call that method from view model. how can i call?
Upvotes: 1
Views: 848
Reputation: 8301
As @tabby suggested i would use public property in viewmodel and bind to
CircleProgressBar
using visibility converter. For binding opactiy you can directly bind it.
Viewmodel . Assuming you have used INotifyPropertyChanged Interface. Wrap the property in INPC.
public bool IsBusy;
public int Opacity;
SomeAction()
{
IsBusy = true;
Thread.Sleep(5000);
IsBusy = false;
Opactiy = 1;
}
Converter
public BooleanVisibiltyConverter: IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
bool flag = false;
if (value is bool)
{
flag = (bool)value;
}
else if (value is bool?)
{
bool? nullable = (bool?)value;
flag = nullable.HasValue ? nullable.Value : false;
}
return (flag ? Visibility.Visible : Visibility.Collapsed);
}
}
XAML
Add the converter to the window resource before consuming it.
<CircularProgressBar Opacity="{Binding Opactiy}" Visibility="{Binding IsBusy, Converter={StaticResource BoolToVis}}"
Upvotes: 1