I would like to add some margin to the left side of WPF TabControl
's TabItem
s. If I use the straightforward Margin="4"
approach, then the margin is applied to every TabItem
, instead I want to move the whole tab item container a bit more to the right. For example, by default it looks like the tabs are 2 pixels to the right, I want to increase that so that I can fit a button to the left side of the tabs.
Your will need to define a new template for the TabControl.
See the example template on MSDN
If you use this template you can change the margin of the HeaderPanel to achieve what you want.
If you need to see the real template being used, you can use Blend to extract the template. You can then modify that.
An alternative is to derive your own TabControl and modify the margin in code-behind, for example:
public class MyTabControl : TabControl
{
public override void OnApplyTemplate()
{
base.OnApplyTemplate();
var panel = Template.FindName("HeaderPanel", this) as FrameworkElement;
if(panel != null)
{
panel.Margin = new Thickness(20,2,2,2);
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With