Click here to Skip to main content
15,889,266 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I want to create some labels and textbox but, if I collapse one then the others below will go up. There is a way to do this in WPF 3.5?

I am using this:
<<pre lang="xml">Window x:Class="FlowLayoutTest.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:wf="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms"
    Title="Window1" Height="300" Width="418" WindowStartupLocation="CenterScreen">
    <Grid ShowGridLines="False">
        <WindowsFormsHost Margin="0,37,0,104" x:Name="WindowsFormsHost">
            <wf:FlowLayoutPanel x:Name="flowLayoutPanel1" >
            </wf:FlowLayoutPanel>
        </WindowsFormsHost>
        <Button Height="23" Margin="0,37,0,0" Name="button1" VerticalAlignment="Top" HorizontalAlignment="Left" Width="75" Click="button1_Click">Button</Button>
    </Grid><

but int the wpf form is not showing anything when I run the application...
Posted
Updated 15-Dec-10 17:24pm
v3
Comments
Venkatesh Mookkan 15-Dec-10 21:42pm    
Mark it as Answer if it helps you
Venkatesh Mookkan 16-Dec-10 1:47am    
I don't see any code for Label or TextBox
Venkatesh Mookkan 16-Dec-10 1:52am    
I have updated the Answer

1 solution

Use StackPanel control as your Layout control

Example:

XML
<Window x:Class="WpfApplication2.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">
    <StackPanel>
        <StackPanel Orientation="Horizontal">
            <TextBlock Text="Name:" VerticalAlignment="Center"/>
            <TextBox Width="200"/>
        </StackPanel>
        <StackPanel Orientation="Horizontal">
            <TextBlock Text="Age:" VerticalAlignment="Center"/>
            <TextBox Width="200"/>
        </StackPanel>
    </StackPanel>
</Window>
 
Share this answer
 
v2
Comments
jalmonte 15-Dec-10 22:27pm    
Can you provide some code example, because I tried that but does not work as I want.
Venkatesh Mookkan 15-Dec-10 22:45pm    
Update your question with what you have tried till now. I will help you.
Venkatesh Mookkan 16-Dec-10 1:52am    
I have updated the Answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900