0

I have grid inside a tabitem. The grid can have from one to n elements, all of the same type as in the picture.

enter image description here

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;
        }
Rare
  • 11
  • 5
  • Post your code and XAML. otherwise it's all speculations. – Federico Berasategui Mar 18 '13 at 16:18
  • Added some info. Ask for more if necessary. I add the elements to the grid via code and move them there. The problem isn't the moving but the fact that they show up outside the grid. – Rare Mar 18 '13 at 16:30
  • I copied and pasted all your code and XAML into a sample project and the issue does not reproduce. Please add the necessary code to reproduce the issue. – Federico Berasategui Mar 18 '13 at 16:39
  • That would be exactly everything. Just add textbox to the grid and move it up. – Rare Mar 18 '13 at 17:14
  • 1
    There's no textbox in your code. Please post the full code. Im NOT going to invent anything in order to reproduce the problem. – Federico Berasategui Mar 18 '13 at 17:15
  • Near-sighteness is usual, don't worry. – Rare Mar 18 '13 at 17:57
  • What exactly is 'Oh Noes'? Is it the label that is on top of the DockPanel? Because there is only the TabControl that is within the DockPanel... If not, what elements are "going out of the grid" (which should not be possible at all)? – Dean Kuga Mar 18 '13 at 19:36
  • I'm sorry for not expressing myself fully. 'Oh noes' is label inside a TabItem, which is inside TabControl, which is inside DockPanel. – Rare Mar 19 '13 at 14:32

0 Answers0