views:

409

answers:

2

Adding item to tab control in VS 2008 WPF app

I am bit of a newbie to WPF. I am using VS 2008 and working with a WPF app.

With the design editor I add a Tab control and then add a new tab. I drop an item like a button onto the the tab control. But instead of actually being in the individual tab the item is almost modal on top of the control.

What am I doing wrong or need to do different?

Edit: Here is example of what XAML is created.

<Window x:Class="TestApp.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Window1" Height="300" Width="300">
    <Grid>
        <TextBox Height="23" Margin="87,80,71,0" Name="textBox1" VerticalAlignment="Top" />
        <TabControl Margin="8,29,1,64" Name="tabControl1">
            <TabItem />
            <TabItem />
            <TabItem />
        </TabControl>
    </Grid>
</Window>
A: 

It looks like the parent of your tab is an active focused element, and whatever you drop on it, its getting added to the parent focused element.

You can right click on Tab control and click on "Select->" your tab control.

And then try adding your button.

Akash Kava
Thank you for looking at this. However it doesn't seem to make it work.Here is an example of what the editor is creating.<Grid> <TabControl Margin="8,29,1,64" Name="tabControl1"> <TabItem /> <TabItem /> <TabItem /> </TabControl> <TextBox Height="23" Margin="87,80,71,0" Name="textBox1" VerticalAlignment="Top" /> </Grid>
Maestro1024
+1  A: 

the visual designer can be a little fiddly, try using blend. that being said, that is also another learning curve. i usually code my xaml in xaml view. then make adjustments using the designer if needed. use xaml to put your elements in the correct container, use the designer to position/layout. i always find it puts lots of ugly margins on elements that dont need them.

your code should be

<Window x:Class="TestApp.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Window1" Height="300" Width="300">
    <Grid>
        <TabControl Margin="8,29,1,64" Name="tabControl1">
            <TabItem>
               <TextBox Height="23" Margin="87,80,71,0" Name="textBox1" VerticalAlignment="Top" />
            </TabItem>
            <TabItem />
            <TabItem />
        </TabControl>
    </Grid>
</Window>

but you already knew that, right? as for one control appearing modally on top of another. in a grid children are rendered top down if you dont use columns and rows, i use this for placing items on top of other items, usually for creating 'fake' modal controls.

Aran Mulholland
That is it. I can manually edit that XAML, which I tried but did not create that TabItem tag correctly.
Maestro1024
oh, cool add the Header property to define the tab namelike :- <TabItem Header="Classes">
Aran Mulholland