星空网 > 软件开发 > ASP.net

WPF WrapPanel与Grid布局

在设计客户端界面时,一些布局元素经常用到.Grid StackPanel Canvas WrapPanel等

下面我们举个案例说明下Grid与WrapPanel一起使用的场景。

WPF WrapPanel与Grid布局

1、如上这种布局,在子元素数量未知的情况下,我们应该使用WrapPanel来布局,子元素会自己换行。

2、然后每一行的元素中,第一个要居左,第二个要居中,第三个要居要。这个应该通过Grid来布局,添加三列,然后对应的元素在每列中设置水平方向。

下面是代码:

1、界面:

<Window x:Class="MainWindow"  ="http://schemas.microsoft.com/winfx/2006/xaml/presentation"  ="http://schemas.microsoft.com/winfx/2006/xaml"  Title="MainWindow" Height="250" Width="500" Loaded="MainWindow_OnLoaded" WindowStartupLocation="CenterScreen">  <Window.Resources>  </Window.Resources>  <Grid>    <ScrollViewer>      <WrapPanel x:Name="MyWrapPanel" Margin="10,0">      </WrapPanel>    </ScrollViewer>  </Grid></Window>

2、后台(语言是VB,其实VB和C#差不多的)

Class MainWindow  Private Sub MainWindow_OnLoaded(sender As Object, e As RoutedEventArgs)    Dim grid As Grid    Dim index = 0    For i As Integer = 0 To 10      If index Mod 3 = 0 Then        grid = New Grid()        grid.Width = 440        grid.Margin = New Thickness(0, 20, 0, 20)        grid.ColumnDefinitions.Add(New ColumnDefinition())        grid.ColumnDefinitions.Add(New ColumnDefinition())        grid.ColumnDefinitions.Add(New ColumnDefinition())        MyWrapPanel.Children.Add(grid)      End If      Dim checkBox = New CheckBox()      Dim value = index Mod 3      If value = 0 Then        checkBox.HorizontalAlignment = HorizontalAlignment.Left      ElseIf value = 1 Then        checkBox.HorizontalAlignment = HorizontalAlignment.Center      ElseIf value = 2 Then        checkBox.HorizontalAlignment = HorizontalAlignment.Right      End If      Controls.Grid.SetColumn(checkBox, value)      grid.Children.Add(checkBox)      index += 1    Next  End SubEnd Class

 




原标题:WPF WrapPanel与Grid布局

关键词:wpf

wpf
*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

PPC广告优化的基本思路:https://www.ikjzd.com/articles/137740
把握顾客:在中东做电商,你要学会玩订阅经济:https://www.ikjzd.com/articles/137741
每日新闻 20201220|先买后付的消费方式将重新振兴中东经济:https://www.ikjzd.com/articles/137742
eBay发布11月英国封锁期间的卖家保护措施:https://www.ikjzd.com/articles/137744
亚马逊突然延迟发货,赶紧做好自查:https://www.ikjzd.com/articles/137745
第三条新改变!亚马逊,开始大规模清零冻结资金:https://www.ikjzd.com/articles/137746
永康白云风景区怎么走 白云山风景区怎么去??:https://www.vstour.cn/a/363181.html
2022世界杯门票如何买?:https://www.vstour.cn/a/363182.html
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流