开发者

GridView HeaderTemplate Lost DataContext

I have a gridview with HeaderTemplate, I put a butt开发者_如何转开发on on the header, and have a command attached to it, my ViewModel never gets called. How do I trace back my ViewModel, seems like it gets "lost".

any ideas ?


using this:

RelativeSource={RelativeSource FindAncestor,  AncestorType={x:Type ListView}}}

will bring me back to my DataContext.


Column HeaderTemplate is a generated control part of the DataGrid and does not have direct VisualTree access to the DataGrid's DataContext, so you have to add RelativeSource AncestorType and explicitly refer to the property via the DataContext

"{Binding DataContext.AllSelected, RelativeSource={RelativeSource AncestorType=Window}}" />

or you can also write this to you top element in template

 DataContext="{Binding DataContext, RelativeSource={RelativeSource AncestorType=DataGrid}}"
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜