WPF WrapPanel and grid layouts

Source: Internet
Author: User

Some layout elements are often used when designing the Client interface. Grid StackPanel Canvas WrapPanel, etc.

Here's a case study of the scenario where grid is used with WrapPanel.

1, such as on this layout, in the case of unknown number of child elements, we should use WrapPanel to layout, the child elements will wrap themselves.

2, then each line of elements, the first to be left, the second to be centered, the third to reside. This should be laid out through a grid, add three columns, and the corresponding elements will be horizontally oriented in each column.

Here's the code:

1. Interface:

<Windowx:class= "MainWindow"xmlns= "Http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x= "Http://schemas.microsoft.com/winfx/2006/xaml"Title= "MainWindow"Height= "+"Width= "$"Loaded= "mainwindow_onloaded"windowstartuplocation= "Centerscreen">    <window.resources>    </window.resources>    <Grid>        <ScrollViewer>            <WrapPanelx:name= "Mywrappanel"Margin= "10,0">            </WrapPanel>        </ScrollViewer>    </Grid></Window>

2, Backstage (language is VB, in fact, VB and C # almost)

ClassMainWindowPrivate SubMainwindow_onloaded (Sender as ObjectE asRoutedEventArgs)DimGrid asGridDimindex =0         forI as Integer=0  to Ten            IfIndexMod 3=0  ThenGrid=Newgrid () grid. Width= thegrid. Margin=NewThickness (0, -,0, -) grid. Columndefinitions.add (Newcolumndefinition ()) grid. Columndefinitions.add (Newcolumndefinition ()) grid. Columndefinitions.add (Newcolumndefinition ()) MyWrapPanel.Children.Add (GRID)End If            DimCheckBox =NewCheckBox ()DimValue = IndexMod 3            IfValue =0  Thencheckbox.horizontalalignment=HorizontalAlignment.LeftElseIfValue =1  Thencheckbox.horizontalalignment=HorizontalAlignment.CenterElseIfValue =2  Thencheckbox.horizontalalignment=HorizontalAlignment.RightEnd IfControls.Grid.SetColumn (CheckBox, value) Grid. Children.add (checkBox) Index+=1        Next    End SubEnd Class

WPF WrapPanel and grid layouts

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.