1

Consider that my ViewModel has the IsBusy propery. Is it possible to have such binding in WPF?

<ProgressBar Visiblity="{Binding IsBusy}" ... />
<Button Visiblity="{Binding !IsBusy}" .../>

Note that I've bound Button's visibility to !IsBusy (Not Busy).

I used to have this on JavaScript MVVM frameworks like knockout.

The expression could be more complex like:

<Button Text="IsBusy && !HasError ? true : false"/>
5
  • 1
    Use IValueConverter. Commented Aug 3, 2014 at 14:03
  • @RohitVats It's too hard to create IValueConverters for all combinations required. Isn't there a more JavaScript like solution!? Commented Aug 3, 2014 at 20:00
  • You cannot have what does not exist. You can, of course, create your own custom binding that parses and attempts to execute the text passed to the binding. Which would probably not be too crazy with the coming of Roslyn. But it makes no sense to argue for the existence of something that doesn't exist. Even though, GOTDAMNIT, it would be super sweet if some fat guy would slide down my chimney and leave me some swag. Wouldn't that be awesome? This should exist! Tell me he exists! Commented Aug 3, 2014 at 20:19
  • @Will maybe I should post another question about creating custom bindings. As I'm familiar with Roslyn, it wouldn't be so hard achieve what I want. Commented Aug 4, 2014 at 10:06
  • Bindings are trivial to make. Try doing it before asking. Commented Aug 4, 2014 at 13:31

1 Answer 1

3

In WPF you need to bind to a property so you cannot do !Busy as you wanted. If you want some complex conditions you should create a specific property for that. If you want to have your output formatted in specific way, you can implement custom value converter (i.e. implement interface IValueConverter).

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.