Results 1 to 12 of 12

Thread: WPF Usercontrol not filling tabs

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2010
    Posts
    11

    WPF Usercontrol not filling tabs

    Hi,

    I'm having a WPF problem that I can't figure out. I have a WPF form that uses a dock panel with LastChildFill=True. The last control in there is a tab control.

    In My code behind I am creating tabs inside the tab control and populating them with user controls. The problem I have is that the user control is not filling the tab vertically, horizantally it resizes with the screen but not vertically. Everything seems to be set to auto and stretch but it just loads at a fixed height.

    Anyone have any suggestions?

    Thanks

  2. #2
    Frenzied Member
    Join Date
    Jul 2008
    Location
    Rep of Ireland
    Posts
    1,380

    Re: WPF Usercontrol not filling tabs

    Xaml / Code please...

  3. #3

    Thread Starter
    New Member
    Join Date
    Feb 2010
    Posts
    11

    Re: WPF Usercontrol not filling tabs

    Here is the XAML for the main page:

    Code:
    <Window
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
        x:Class="MainWindow" 
        Title="Main Page" Height="768" Width="1024" mc:Ignorable="d" Foreground="Black" 
        Name="MainWindow">
        <Window.Resources>
        		
        </Window.Resources>
            
        <Window.Background> 
        	<LinearGradientBrush EndPoint="0.5,1" MappingMode="RelativeToBoundingBox" StartPoint="0.5,0">
        		<GradientStop Color="#FFBAC8D6"/>
        		<GradientStop Color="#FFBAC8D6" Offset="1"/>
        		<GradientStop Color="#FFFDFDFD" Offset="0.492"/>
        	</LinearGradientBrush>
        </Window.Background>
    	<DockPanel LastChildFill="True" Name="MyDock">				
            <Grid  Height="25"  DockPanel.Dock="Top">
                <Menu x:Name="myMenu" Background="{x:Null}">
                    <MenuItem x:Name="myFileMenuItem" Header="_File"  >
                        <MenuItem Header="_Mail Message" InputGestureText="Ctrl+N" >
                        </MenuItem>
                        <MenuItem Header="_Exit" InputGestureText="Ctrl+N" >
                        </MenuItem>
                    </MenuItem>
                    <MenuItem x:Name="myWindowMenu" Header="_Windows"  >
                        <MenuItem Header="_Window Order" InputGestureText="Ctrl+W" Name="WindowOrder" >
                        </MenuItem>
                        <MenuItem Header="Window _Issuing" InputGestureText="Ctrl+I" Name="WindowIssuing" >
                        </MenuItem>
                    </MenuItem>
                    <MenuItem x:Name="myConsMenu" Header="_Conservatories"  >
                        <MenuItem Header="_Conservatory Order" InputGestureText="Ctrl+N" Command=""  >
                        </MenuItem>
                    </MenuItem>
                    <MenuItem x:Name="MyCustomerService" Header="_Customer Service"  >
                        <MenuItem Header="Sales Analysis" InputGestureText="Ctrl+N"  >
                        </MenuItem>
                        <MenuItem Header="Serice Calls" InputGestureText="Ctrl+N"  >
                        </MenuItem>
                    </MenuItem>
                    <MenuItem x:Name="MyFinance" Header="_Finance"  >
                        <MenuItem Header="Menu Item" InputGestureText="Ctrl+N"  >
                        </MenuItem>
                    </MenuItem>
                    <MenuItem x:Name="myHelpManagement" Header="_Management"  >
                        <MenuItem Header="_Forecasting" InputGestureText="Ctrl+N"  >
                        </MenuItem>
                        <MenuItem Header="_Key Performance Indicators" InputGestureText="Ctrl+N"  >
                        </MenuItem>
                    </MenuItem>
                    <MenuItem x:Name="myHelpMenu" Header="_Help"  >
                        <MenuItem Header="_About" InputGestureText="Ctrl+N"  >
                        </MenuItem>
                    </MenuItem>
                </Menu>
            </Grid>
    		
            <local:StatusBar DockPanel.Dock="Bottom"/>
    
            <TabControl Width="Auto" Name="TabControl1"  Margin="100,10,100,100" Padding="0" DockPanel.Dock="Left" 
                        Height="Auto" MinHeight="250"  MinWidth="350">
                <TabControl.Effect>
                    <DropShadowEffect/>
                </TabControl.Effect>
                <TabControl.Background>
                    <SolidColorBrush />
                </TabControl.Background>
            </TabControl>
         
    	</DockPanel>
            
    </Window>
    Last edited by SKinsey; Apr 20th, 2010 at 08:00 AM.

  4. #4

    Thread Starter
    New Member
    Join Date
    Feb 2010
    Posts
    11

    Re: WPF Usercontrol not filling tabs

    And for the user control:

    Code:
    <UserControl
    	xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    	xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    	xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    	xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    	xmlns:ed="http://schemas.microsoft.com/expression/2010/drawing" 
        	mc:Ignorable="d"
    	x:Class="WindowOrder"
    	x:Name="WindowOrder"
        Width="Auto" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Height="Auto"
        BorderThickness="0" Padding="0" Margin="0" BorderBrush="{x:Null}">
    	<UserControl.Background>
    		<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
    			<GradientStop Color="Black"/>
    			<GradientStop Color="White" Offset="1"/>
    		</LinearGradientBrush>
    	</UserControl.Background>
        
        <Grid Height="Auto" VerticalAlignment="Stretch">
            <Grid.Triggers>
                <EventTrigger RoutedEvent="Window.Loaded">
                    <EventTrigger.Actions>
                        <BeginStoryboard>
                            <Storyboard TargetProperty="Opacity">
                                <DoubleAnimation From="0" To="1" Duration="0:0:0.5"/>
                            </Storyboard>
                        </BeginStoryboard>
                    </EventTrigger.Actions>
                </EventTrigger>
            </Grid.Triggers>
            <Grid.OpacityMask>
                <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                    <GradientStop Color="Black" Offset="0"/>
                    <GradientStop Color="White" Offset="1"/>
                </LinearGradientBrush>
            </Grid.OpacityMask>
            <Grid.Background>
                <LinearGradientBrush EndPoint="0.5,1" MappingMode="RelativeToBoundingBox" StartPoint="0.5,0">
                    <GradientStop Color="#FF9EBCC2" Offset="1"/>
                    <GradientStop Color="White"/>
                </LinearGradientBrush>
            </Grid.Background>
            <Image Height="50" Margin="0" VerticalAlignment="Top" Source="headerback.png" Stretch="Fill">
                <Image.Effect>
                    <BlurEffect/>
                </Image.Effect>
            </Image>
            <Image HorizontalAlignment="Left" Height="35" Margin="8,8,0,0" VerticalAlignment="Top" Width="35" Source="windoframe.png"/>
            <Label HorizontalAlignment="Left" Margin="57,8,0,0" VerticalAlignment="Top" Content="Windows" Foreground="White" FontSize="24" FontWeight="Bold"/>
            <ListBox Style="{StaticResource RadioButtonList}" Width="100" HorizontalAlignment="Left" Margin="680,129,0,0" 
                     VerticalAlignment="Top" BorderThickness="1" Padding="5">
                <ListBox.Background>
                    <SolidColorBrush />
                </ListBox.Background>
                <ListBoxItem Content="Okay" />
                <ListBoxItem Content="Hold" />
                <ListBoxItem Content="Query" />
                <ListBoxItem Content="Cancelled" />
                <ListBoxItem Content="Made" />
                <ListBox.BorderBrush>
                    <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                        <GradientStop Color="#FF617585" Offset="0" />
                        <GradientStop Color="#FFDAE6E8" Offset="1" />
                    </LinearGradientBrush>
                </ListBox.BorderBrush>
            </ListBox>
            <Label Content="Received:" HorizontalAlignment="Left" Margin="126,107,0,0" VerticalAlignment="Top"/>
            <Label Content="Ordered:" HorizontalAlignment="Left" Margin="126,135,0,0" VerticalAlignment="Top"/>
            <Label Content="Planned:" HorizontalAlignment="Left" Margin="126,163,0,0" VerticalAlignment="Top"/>
            <Label Content="Checked:" HorizontalAlignment="Left" Margin="126,191,0,0" VerticalAlignment="Top"/>
            <Label Content="Status:" HorizontalAlignment="Left" Margin="685,106,0,0" VerticalAlignment="Top"/>
            <Label Content="Other:" HorizontalAlignment="Left" Margin="126,302,0,0" VerticalAlignment="Top"/>
            <Label Content="Customer:" HorizontalAlignment="Left" Margin="126,246,0,0" VerticalAlignment="Top"/>
            <Label Content="Customer Ref:" HorizontalAlignment="Left" Margin="126,274,0,0" VerticalAlignment="Top"/>
            <Label Content="Reason:" HorizontalAlignment="Left" Margin="126,218,0,0" VerticalAlignment="Top"/>
            <DatePicker HorizontalAlignment="Left" Margin="200,103,0,0" VerticalAlignment="Top"/>
            <DatePicker HorizontalAlignment="Left" Margin="200,159,0,0" VerticalAlignment="Top"/>
            <DatePicker HorizontalAlignment="Left" Margin="200,131,0,0" VerticalAlignment="Top"/>
            <DatePicker HorizontalAlignment="Left" Margin="200,187,0,0" VerticalAlignment="Top" />
            <ComboBox Height="23" HorizontalAlignment="Left" Margin="200,218,0,0" Name="cmbReason" VerticalAlignment="Top" Width="180" />
            <TextBox Height="23" HorizontalAlignment="Left" Margin="200,246,0,0" Name="txtCustomerID" VerticalAlignment="Top" Width="40" />
            <TextBox Height="23" HorizontalAlignment="Left" Margin="200,274,0,0" Name="txtCustomerName" VerticalAlignment="Top" Width="180" />
            <TextBox Height="23" HorizontalAlignment="Left" Margin="246,246,0,0" Name="txtCustomerRef" VerticalAlignment="Top" Width="134" />
            <TextBox Height="23" HorizontalAlignment="Left" Margin="200,302,0,0" Name="TextBox1" VerticalAlignment="Top" Width="180" />
            <ComboBox Height="21" HorizontalAlignment="Right" Margin="0,16,10,0" Name="cmbSearch" VerticalAlignment="Top" Width="174">
                <ComboBoxItem Content="Contract" />
                <ComboBoxItem Content="Customer ID" />
                <ComboBoxItem Content="Customer Ref" />
                <ComboBoxItem Content="Name" />
                <ComboBoxItem Content="Received" />
                <ComboBoxItem Content="Status" />
                <ComboBoxItem Content="Advanced..." />
            </ComboBox>
            <TextBox HorizontalAlignment="Right" Margin="0,16,32,0" TextWrapping="Wrap" Text="Search" VerticalAlignment="Top" Width="167"/>
            <Label Content="Window Order" Margin="126,65,0,0" VerticalAlignment="Top" FontSize="16" FontWeight="Bold" BorderThickness="0,0,0,2" Height="25" Foreground="#FF004281" BorderBrush="#FF002166"/>
            <Rectangle Fill="#FFF4F4F5" Height="1" Margin="126,94,6,0" Stroke="Black" VerticalAlignment="Top"/>
            <Grid Width="300" Margin="380,95,6,106" HorizontalAlignment="left" VerticalAlignment="Top" >
                <ComboBox Height="23" HorizontalAlignment="Left" Margin="80,6,0,0" Name="cmbComponent" VerticalAlignment="Top" Width="91" 
                          IsReadOnly="False" DataContext="{Binding Source={StaticResource ComponentProvider}}" ItemsSource="{Binding Path=ComponentName}" IsEditable="False">
                    <!--<ComboBox.ItemsSource>
                        <Binding Path="ComponentName"></Binding>
                    </ComboBox.ItemsSource>-->
                    <!--<ComboBox.ItemTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding Path=ComponentName}" />
                        </DataTemplate>
                    </ComboBox.ItemTemplate>-->
                </ComboBox>
                <Label Content="Components:" HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top" />
                <Button Content="Add" Height="23" HorizontalAlignment="Left" Margin="219,6,0,0" Name="Button1" VerticalAlignment="Top" Width="75" />
                <ListBox Height="198" HorizontalAlignment="Left" Margin="10,32,0,0" Name="ListBox1" VerticalAlignment="Top" Width="284" >
    
                    <ListBox.BorderBrush>
                        <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                            <GradientStop Color="#FF617585" Offset="0" />
                            <GradientStop Color="#FFDAE6E8" Offset="1" />
                        </LinearGradientBrush>
                    </ListBox.BorderBrush>
                </ListBox>
                <ComboBox Height="23" HorizontalAlignment="Right" Margin="0,6,87,0" Name="cmbUnits" VerticalAlignment="Top" Width="36" IsEditable="True" SelectedIndex="0">
                    <ComboBoxItem Content="1" />
                    <ComboBoxItem Content="2" />
                    <ComboBoxItem Content="3" />
                    <ComboBoxItem Content="4" />
                    <ComboBoxItem Content="5" />
                </ComboBox>
            </Grid>
            <Rectangle Height="40" Stroke="Transparent" VerticalAlignment="Bottom">
                <Rectangle.Fill>
                    <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0" Opacity="0.2">
                        <GradientStop Color="#FF1F6BD4" Offset="1"/>
                        <GradientStop Color="White"/>
                    </LinearGradientBrush>
                </Rectangle.Fill>
            </Rectangle>
            <Button Content="Delete" HorizontalAlignment="Right" Margin="0,67,6
                    ,0" VerticalAlignment="Top" Width="75"/>
            <Button Content="Add" HorizontalAlignment="Right" Margin="0,67,164,0" VerticalAlignment="Top" Width="75"/>
            <Button Content="Edit" HorizontalAlignment="Right" Margin="0,67,85
                    ,0" VerticalAlignment="Top" Width="75"/>
            <Button Content="First" HorizontalAlignment="Right" Margin="0,0,243,8" VerticalAlignment="Bottom" Width="75"/>
            <Button Content="Last" Margin="0,0,6,8" VerticalAlignment="Bottom" Width="75" HorizontalAlignment="Right" />
            <Button Content="Prev" HorizontalAlignment="Right" Margin="0,0,164,8" VerticalAlignment="Bottom" Width="75"/>
            <Button Content="Next" HorizontalAlignment="Right" Margin="0,0,85,8" VerticalAlignment="Bottom" Width="75"/>
            <Label Content="Label" Height="28" HorizontalAlignment="Left" Margin="382,352,0,0" Name="Label1" VerticalAlignment="Top" />
        </Grid>      
    </UserControl>

  5. #5

    Thread Starter
    New Member
    Join Date
    Feb 2010
    Posts
    11

    Re: WPF Usercontrol not filling tabs

    And finally the tab wire up code behind:

    Code:
    Dim MyTab As New TabItem
    MyTab.Name = "tabWindowOrder"
    MyTab.Header = "Windows"
    MyTab.Content = New WindowOrder
    Me.TabControl1.Items.Add(MyTab)
    I'm pretty new to WPF so this could all be pretty messy code.

  6. #6

    Thread Starter
    New Member
    Join Date
    Feb 2010
    Posts
    11

    Re: WPF Usercontrol not filling tabs

    I've also attached an image to show the problem, I want the control to fill the tab but you can see all the white space around it. If you rezise screen, the tab content stays the same size.

    Name:  snipped.JPG
Views: 10763
Size:  62.8 KB

  7. #7
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    Re: WPF Usercontrol not filling tabs

    I just copied and pasted all of your XAML and code and it works fine for me... I can maximise the window and the user control within the tab stretches to fit.
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  8. #8

    Thread Starter
    New Member
    Join Date
    Feb 2010
    Posts
    11

    Re: WPF Usercontrol not filling tabs

    That is very strange, although there is one massive thing that I stupidly forgot to mention lol

    I am using Visual Studio 2010 and 4 Framework. I realise this is a release candidate so maybe it's a bug in there.

  9. #9
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    Re: WPF Usercontrol not filling tabs

    The full version of Visual Studio 2010 is out now so try downloading and installing that (the Express version is free as with previous versions) as that is what I used to test your project.

    By the way, nice looking app
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  10. #10

    Thread Starter
    New Member
    Join Date
    Feb 2010
    Posts
    11

    Re: WPF Usercontrol not filling tabs

    Very strange, I just download the new version and it still does it for me. Maybe I'll create a test app with my XAML like you did and test that.

    Glad you like it by the way I come from a web design background so WPF is SO much more fun than winforms.

    Update: I can see whats wrong, I'm using an application resource called "WhistlerBlue" for buttons stylings etc. That is clearly overriding the default settings for the tab control.
    Last edited by SKinsey; Apr 20th, 2010 at 11:13 AM.

  11. #11
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    Re: WPF Usercontrol not filling tabs

    Ahhh cool, I think I commented out the reference to that resource when I copied your code as you didnt post the definition for that (yeah I should have mentioned that...). So its all working as it should now?
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  12. #12

    Thread Starter
    New Member
    Join Date
    Feb 2010
    Posts
    11

    Re: WPF Usercontrol not filling tabs

    Yes I removed the section for tab control formatting from the resource file and it works perfectly now. Thanks for the help.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width