I have grid inside a tabitem. The grid can have from one to n elements, all of the same type as in the picture.
Now, I've been playing with this for a loong time and searching for answers, but can't find one. The problem is, elements can go out of the grid (only from the top and only until the dockpanel comes), causing some annoying things like in the picture. I'm hoping someone has some idea how to fix this.
Now, what have I tried?
- Adding rectangle to the top, with higher ZIndex than the elements.
- Hiding the elements when they hit the top of the grid -> not smooth.
- Not really others because I ran out of ideas.
EDIT
Whole XML:
<Page x:Class="WpfBrowserMindmap.Page1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="473" d:DesignWidth="604"
Title="Page1">
<Grid Loaded="Grid_Loaded" SizeChanged="Grid_SizeChanged">
<Label Height="28" HorizontalAlignment="Left" Margin="440,12,0,0" Name="label1" VerticalAlignment="Top" Content="Label1" AllowDrop="False" />
<DockPanel Height="100" HorizontalAlignment="Left" Margin="12,100,0,0" Name="dockPanel1" VerticalAlignment="Top" Width="200">
<TabControl Height="100" Name="tabControl1" Width="200" VerticalAlignment="Top" HorizontalAlignment="Left" SelectionChanged="tabControl1_SelectionChanged">
</TabControl>
</DockPanel>
</Grid>
</Page>
AddTab-function:
private TabItem AddTab()
{
TabItem item = new TabItem();
item.Header = "Empty work";
Grid grid = new Grid();
grid.Background = new SolidColorBrush(Colors.Transparent);
UserControl control = new UserControl();
control.Content = grid;
item.Content = control;
tabControl1.Items.Add(item);
return item;
}