简体   繁体   中英

WPF listbox two items side by side

Basically I want to create a form. It might be a little long after I am done so I wanted to use a list box so the form is scrollable. I would like to have a label with a text box next to it for input from the user. How can I have the label and text box side by side in the list box?

Also, if anyone has any other suggestions on how to create a form please let me know.

Do not use a ListBox to add scrolling capability, use the ScrollViewer for that.

Could you sketch/draw an image that explains your ideas?

<Grid>
    <ScrollViewer>
         <Grid ScrollViewer.VerticalScrollBarVisibility="Auto"
              ScrollViewer.HorizontalScrollBarVisibility="Disabled">
            <Grid.ColumnDefinitions>
                <ColumnDefinition />
                <ColumnDefinition />
            </Grid.ColumnDefinitions>
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition  Width="auto" />
                    <ColumnDefinition />
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                    <RowDefinition Height="auto" />
                    <RowDefinition Height="*" />
                </Grid.RowDefinitions>
                <Label Target="{Binding ElementName=textBlock}"
                       VerticalAlignment="Center">_Name:</Label>
                <TextBox Grid.Column="1"
                         x:Name="textBlock"
                         VerticalAlignment="Center"
                         Text="Enter text here" />
            </Grid>                
            <Border Grid.Column="1">
                <TextBlock Text="Anything you like" />
            </Border>
        </Grid>
    </ScrollViewer>
</Grid>

There are many other options. Eg, you could put the ScrollViewer inside the Border in my example. That would make the content of the Border scrollable instead of the entire form. Key is to determine what you want it to look like and how you want it to behave.

The best way to do that is by drawing or prototyping in a designer such as Expression Blend.

在ScrollViewer中包装您的包含面板(例如网格)-http: //msdn.microsoft.com/zh-cn/library/ms750665.aspx

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM