WPF ReadOnly Dependency Properties using MVVM

前端 未结 4 1876
心在旅途
心在旅途 2020-12-10 16:47

I\'ve recently overridden the DevXpress WPF grid to give myself a SelectedObject property that I can access from my loosely bound ViewModel.

I\'ve made a SelectedObj

4条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-10 16:52

    The purists among us would otherwise expect that a true read-only DependencyProperty scenario should ideally work as expected. But for apparent WPF one- and two-way data binding expectations, I agree along these lines.

    However, I worked around this in my DependencyObject view model by providing a full DependencyProperty, but only providing a get-only property exposing the details I wanted. Not truly read-only in the WPF MVVM sense, but since I chose not to implement the setter, it works for my purposes.

    I agree with other folks, any more code than that breaks MVVM in the strictest sense.

提交回复
热议问题