tags:

views:

49

answers:

1

Trying to develop using MVVM:

I have this Csla.PropertyStatus control that is created in my ViewModel. I want to add it in the xaml (via binding, i think) and set some additional properties there (such as the target).

I don't know how i could do that, not even if that is possible.

I was looking for something like

<csla:PropertyStatus Instance="{Binding Path=MyStatus}" 
                     Target="{Binding ElementName=txtTextBox}" 
                     Grid.Column="2" Grid.Row="0"/>

Is that possible somehow?... i NEED to create it in the ViewModel because i need to set some property that the view (XAML) is not allowed to know about.

Edit: The property i'm talking about is the model. The PropertyStatus needs a reference to the business object to perform the validation. But considering the paradigm of MVVM (or as i understand it), the view should be decoupled from the model, and should only know about the ViewModel. I might change that approach, though...

+1  A: 

You CAN'T do this. BTW, the view is all about UI controls and their properties, so saying the view is not allowed to "know about" a property on one of its elements is a bit... extreme. A description of what you are trying to accomplish here might help in providing you with a decent answer.

Will
hmmm, you might be able to bind to the Content property of a ContentControl, but that would be bad design imho.
Will
i updated the question for clarification; thanx for the answer, Will!
Teodor
Your interpretation of MVVM is not only rigid, but also not exactly correct. You can't hide models from the view; the view binds to models provided by the ViewModel. Do your requirements state that the view has to be able to bind to any number of possible models? Relax, guy. Go with the flow, man. Bind to those models! Wear flowers in your hair! Tune in, turn on, don't fear the reaper, etc.
Will
Or, look at it from this angle--exactly where in the big book of MVC/MVVM does it say that the ViewModel shall create UI elements? Aren't UI elements the sole provenance of the View? Isn't it a violation of the ViewModel's contract to be dabbling in UI elements? How dare you break the solemn vow of ViewModelers! I should throw you in MVVM jail! We live by the MVVM book, we die by the MVVM book. Any derivation from the one path will result in dire consequences! We shall excoriate the deviancy from you with fire and sharp implements of torture! REPENT!
Will