0

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

4

4 回答 4

3

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/

于 2013-01-16T18:04:26.090 回答
2

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

于 2013-01-16T09:18:23.097 回答
1

Use a ContentPresenter:

<ContentPresenter Content="{Binding ButtomControl}"/>

Anyway, it's odd to bind to a control!

于 2013-01-16T09:27:49.960 回答
0

Thanks you all, all answers was valuable

Finally, i used DataTriggers, as described here: MVVM : how to switch between views using DataTemplate + Triggers

Thanks

于 2013-01-17T12:16:32.053 回答