开发者

Wpf databinding changing datacontext/itemssource

I have View and ViewModel. The DataContext of the View is set to the ViewModel. In the ViewMo开发者_如何学JAVAdel I have collection of items and also few properties which I want to bind to View.

In the View I have ComboBox or GridView and their ItemsSource properties are bound to the ViewModel collection. When I have concrete column in the grid and I am binding it I put the name of a property in object from collection and it is working fine. In other words, DataContext of the grid is set to the collection. But now I want to bind one thing in grid to a property in my ViewModel, not to an object from the collection. For example it can be Width of column or whatever, or even maybe content of whole column. So how do I do that?


This is the easy solution:

Binding="{Binding RelativeSource={RelativeSource FindAncestor,  AncestorType={x:Type Window}}, Path=DataContext}}"
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜