WPF MVVM hiding button using BooleanToVisibilityConverter

后端 未结 2 912
天涯浪人
天涯浪人 2020-12-15 17:50

In my WPF application I am trying to change the visibility of a button depending on the options chosen by a user. On load I want one of the buttons to not be visible. I am u

2条回答
  •  春和景丽
    2020-12-15 18:16

    For starters mate, if you're using a Command, then you don't need to bind IsEnabled, the command implementation should decide this.

    Secondly, the binding of a ViewModel to a View tends to happen at a bit of a later stage, so it's best to also set a default value for the binding, like so

    Visibility="{Binding ButtCancel, Converter={StaticResource BoolToVis}, FallbackValue=Hidden}"
    

    Third, as Mike pointed out, ensure that your property is public, since the ViewModel and the View are two separate classes.

提交回复
热议问题