Question

I am writing a text editor in WPF and I seem to have a strange border that I can't remove.

I've got a grid with a tabcontrol, and when a user selects "File -> New", I programatically add a new tabitem to the tabcontrol. I'm setting the tabitem content to an instance of WindowsFormsHost in order to host the ScintillaNet WinForms control.

Here's the problem: http://i.stack.imgur.com/kotSb.png

I'm pretty sure the border is not coming from the WinForms control itself, as I've used it elsewhere in the same configuration and it has no border.

The red border you see is added by me to highlight the problem (in the method that is responding to File -> New), with the following code:

tabControl.BorderThickness = new Thickness(3, 3, 3, 3);
tabControl.BorderBrush = Brushes.Red;
tabControl.Items.Add(tab);
tab.Focus();

Any ideas where this inner grey border is coming from?

Was it helpful?

Solution

That is the Padding on the TabControl, which is a margin it applies to the hosted child element. See Alignment, Margins, and Padding Overview. It is set to 4 in the default TabControl style. Try setting the Padding to zero explicitly:

tabControl.BorderThickness = new Thickness(3, 3, 3, 3);
tabControl.BorderBrush = Brushes.Red;
tabControl.Padding = new Thickness(0);
tabControl.Items.Add(tab);
tab.Focus();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top