Search code examples
wpfmvvmpropertiescontrolsencapsulation

Binding control WPF break encapsulation


First of all, I use MVVM pattern in WPF.

I have a ViewModel which contains a grid. In order to render the grid in the view, I have to do the property of the grid public.

In this way the encapsulation of the control has been broken because if I want to use the control in other view models the grid is available for modifications.

Is there some solution about this problem?

I think Microsoft has screwed up, what is your opinion?


Solution

  • a viewmodel should not have a grid :) just the view. the viewmodel just have a collection for your grids itemssource.

    edit: maybe what you want is some kind of usercontrol with Dependency Properties?