tags:

views:

93

answers:

3
+2  Q: 

MVVM WPF Question

I am using MVVM pattern to implement a WPF App. My question is, I have a Yes and No Radio Buttons and a text box.

ex: Do you own a Car: Yes , No (Radio Buttons) Enter Model:__________ (Text Box)

if user selects No, i am disabling it. if user selects Yes and leaves 'Enter Model' Textbox empty, i want to display a message or change background(like the way AdornerElement does). How can i achieve this.

Thank you, Re@@y.

+2  A: 

Actually you don't need to apply MVVM for this particular problem, since it is totally a UI related thing. You can have IsEnabled property bind to the yesRadiobutton.IsChecked property to make it disable while you select noRasioButton. And again You can use BoolToVisibilityConverter and bind the same to a TextBlock to display a message. Same for a Rectangle with particular background

Jobi Joy
+1  A: 

What I would do, if your desperate to use MVVM, is create a number of custom type converters (http://msdn.microsoft.com/en-us/library/ayybcxe5.aspx).

So on a Textblock, bind the text to the IsChecked property of the radio buttons, then using the converter, translate that boolean into a custom string that you want to display.

For the background of the form, bind the Background element to the appropriate control's IsChecked and use another type converter to convert from bool to Color.

Thats, in my understanding, how to do it via MVVM.

Alastair Pitts
This is what I proposed above too, and it is not really MVVM it purely a XAML work, So that no C# code or ViewModel required to do our solution.
Jobi Joy
Thanks for the reply .. i will check it...
Rey
+1  A: 

I would implement this using triggers only. No need to complicate things by using MVVM when you don't need to.

Kilhoffer