WPF 動態布局Grid

來源:互聯網
上載者:User

標籤:style   class   blog   code   http   tar   

 1 //開啟線程載入 2             Action a = () => 3             { 4                 var row = 7; 5                 var column = 9; 6  7                 var path = "../../face_img/"; 8                 var files = Directory.GetFiles(path); 9                 for (var i = 0; i < row; i++)10                 {11                     faceGrid.RowDefinitions.Add(new RowDefinition());12                 }13                 for (var i = 0; i < column; i++)14                 {15                     faceGrid.ColumnDefinitions.Add(new ColumnDefinition());16                 }17                 var index = 0;18                 for (var i = 0; i < row; i++)19                 {20                     for (var j = 0; j < column; j++, index++)21                     {22                         if (index < files.Length)23                         {24                             var btn = new Button { Width = 25, Height = 25 };25                             var image = new GifImage { Source = System.IO.Path.GetFullPath(files[index]), Stretch = Stretch.Fill };26                             btn.Click += btn_Click;27                             image.ToolTip = "["+ System.IO.Path.GetFileName(files[index]) + "]";28                             btn.Tag = "[" + System.IO.Path.GetFileName(files[index]) + "]";29                             image.OpacityMask = this.Background;30                             image.Width = btn.Width-1;31                             image.Height = btn.Height-1;32                             btn.BorderBrush = Brushes.WhiteSmoke;33                             btn.Background = Brushes.White;34                             btn.Content = image;35                             Grid.SetRow(btn, i);36                             Grid.SetColumn(btn, j);37                          38                             faceGrid.Children.Add(btn);39                         }40                     }41                 }42             };43             this.faceGrid.Dispatcher.Invoke(a);
layout

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.