How do I bind a close button in a TabControl header to a command in the window's ViewModel?

后端 未结 1 784
粉色の甜心
粉色の甜心 2021-01-16 11:55

I\'m working on a tool and want to add a close button to the tabs in a TabControl. I can\'t figure out how to make the Command property of the button bind to the appropriate

相关标签:
1条回答
  • 2021-01-16 12:51

    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.

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

    Hope this helps

    0 讨论(0)
提交回复
热议问题