正确且正确地将控件/ UIElement可见性绑定到Property MVVM C#WPF

Pro*_*rof 0 c# wpf binding mvvm viewmodel

我是MVVM的新手,我一直在构建我的ViewModel.我有一个ViewModel,它包含一个ICommand,然后通过命令按钮绑定到我的View中.该ICommand原因的过程对我的视图模型,然后调用进一步大幅缓慢的过程被调用.在执行此过程时,我想让控件UIElement的可见性变为可见,然后在过程完成后隐藏(我打算绑定标签并确定进度条的可见性)

例如,在我的视图模型中,我有

public void calledFromCommandButton() {
RaisePropertyChange("Starting");
superLongProcedure();
RaisePropertyChange("Finished");

}
Run Code Online (Sandbox Code Playgroud)

这只是感觉有点傻,不得不提出2个不同的属性变化,因此,我认为我做错了.我想我可以通过一个属性更改和转换器来实现吗?

那么,将UIElement可见性绑定到属性更改事件的正确和正确方法是什么?

谢谢托马斯

Bri*_*n S 6

我建议使用单个boolean属性(IsWorking或其他),然后使用BooleanToVisibilityConverter显示和隐藏按钮.所以,它看起来像:

<Window ...>
    <Window.Resources>
       <BooleanToVisibilityConverter x:Key="TrueToVisibleConverter"/>
    </Window.Resources>
     ...
    <Button x:Name="CancelButton" Content="Cancel" Visiblity="{Binding IsWorking, Converter={StaticResource TrueToVisibleConverter}}"/>
     ...
</Window/>
Run Code Online (Sandbox Code Playgroud)