Reputation: 1565
i have view:
<Grid>
<!--Some Stuff-->
<Control XXX="{Binding ButtomControl}"/>
<!--Some Stuff-->
</Grid>
i have VM:
public sealed class SelectionDialogV3VM : PropertyChanges
{
// Some Stuff
public Control ButtomControl
{
get{return _buttomControl;}
set
{
_buttomControl = value;
OnPropertyChanged("ButtomControl");
}
}
// Some Stuff
}
My objective: in run time change some view (ButtomControl) inside of my main view. But, i can not do proper binding because i do not know the XXX property.
thanks
Upvotes: 2
Views: 4908
Reputation: 1565
Thanks you all, all answers was valuable
Finally, i used DataTriggers, as described here: MVVM : how to switch between views using DataTemplate + Triggers
Thanks
Upvotes: 0
Reputation: 1357
I just wanted to add something else:
Referencing a UI control in the view model should be avoided at all cost.
If you want to switch the view via the view model, try using DataTemplates and a ContentControl instead.
See:
http://rachel53461.wordpress.com/2011/05/28/switching-between-viewsusercontrols-using-mvvm/
Upvotes: 3
Reputation: 2947
Use a ContentPresenter:
<ContentPresenter Content="{Binding ButtomControl}"/>
Anyway, it's odd to bind to a control!
Upvotes: 1
Reputation: 9265
Try something like this :
<ContentControl Content="{Binding ButtomControl}"/>
But honestly, having a property in your ViewModel of type Control
is not a good omen :D
Upvotes: 4