且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何将 TabControl 标头中的关闭按钮绑定到窗口 ViewModel 中的命令?

更新时间:2021-11-12 03:02:28

也许这对你有用,沿着这些方向...
绑定按钮的数据上下文(或您可能需要的任何其他地方)...

Maybe this could work for you, all along those lines...
Bind Button's data context (or anywhere else you might need)...

DataContext="{Binding RelativeSource={RelativeSource AncestorType=Window}, Path=DataContext}"  

这提供了您在上方"某处有一个窗口的情况.

This providing you have a window somewhere 'above' it.

或者,如果您有特定的 Name,您可以使用 ElementName 类似于 RelativeSource.

Or if you have specific Name you can use ElementName similarly to RelativeSource.

希望能帮到你