views:

58

answers:

1

In XAML (Root is a UserControl), I have defined a grid with two columns. In a ViewModel layer, I have defined a property as UserControl. The ViewModel is set as DataContext of the XAML.

How I can bind this property of type UserControl declarative to the grid?

Thanks

A: 

I'm not sure how to answer your literal question, but it sounds like you are taking the wrong approach here - your presentation layer (UserControl) is getting mixed in with your business logic (view model).

I would create a property that is an observable collection of the type that is populating your datacontext. You can then bind the ItemsSource property of the grid to that property, which should give you the outcome you are after.

I hope that helps.

Travis
Thanks, I had the same thoughts. But I don't think there's a problem, the Presentation layer demands only a usercontrol (property) to bind, same dependencies when the binding happens via a usercontrol collection (property).I didn't use this approach because:First, I don't want a grid filled with some 'widgets', in any order, any layout. The columns are predefind.And second, why using a collection when I have only one item to bind?
EricSch