Reputation: 437
I'm making a WPF application with a TabControl
in it. In there, I have a TabItem
containing a custom UserControl
such as this:
<TabItem>
<local:SomeUserControl/>
</TabItem>
I would like to bind the Header
property of that tab to a property of the SomeUserControl
element. I've tried simply making a public string property SomeHeader
in the user control and binding it like this:
<TabItem Header="{Binding Content.SomeHeader}">
But it didn't work, as the header remained empty when the application was launched. I get the feeling I'm misunderstanding how data binding works here, but I don't know where I went wrong. So, how would I bind this property to the tab's header?
Upvotes: 0
Views: 321
Reputation: 437
Nevermind, I figured it out.
I needed to set the binding Path
to Content.SomeHeader
and RelativeSource
to {RelativeSource Self}
, that way the path will look for properties relative to its own object.
<TabItem Header="{Binding Path=Content.SomeHeader, RelativeSource={RelativeSource Self}}">
<local:SomeUserControl/>
</TabItem>
Upvotes: 1