WPF學習日誌 ~ WrapPanel ~

摘要:WPF學習日誌 ~ WrapPanel ~

這篇我們來測試一下第二個"容器",WrapPanel,它是怎麼來幫我們做排版的動作呢?
千言萬語勝不過按一下"F5",讓我們直接瞧瞧程式碼吧


    Private Sub Window1_Loaded(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles Me.Loaded
        Dim wp As New WrapPanel
        wp.Background = Brushes.AliceBlue
        Me.Title = "Test WrapPanel"
        Me.Content = wp
        For z As Integer = 0 To 25
            Dim btn As New Button
            btn.Name = "Button" & z
            btn.Content = "Button _" & Chr(&H41 + z)
            btn.VerticalAlignment = Windows.VerticalAlignment.Center
            btn.HorizontalAlignment = Windows.HorizontalAlignment.Center
            AddHandler btn.Click, AddressOf Button_Click
            wp.Children.Add(btn)
        Next
    End Sub

    Private Sub Button_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
        MessageBox.Show(CType(e.Source, Button).Content.ToString)
    End Sub

 

執行程式之後去改變視窗的大小,之後就可以看到WrapPanel是怎麼樣去做排版的動作了。