码迷,mamicode.com
首页 > 其他好文 > 详细

WPF 动态布局Grid

时间:2014-06-27 19:39:49      阅读:158      评论:0      收藏:0      [点我收藏+]

标签:style   class   blog   code   http   tar   

bubuko.com,布布扣
 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

 

WPF 动态布局Grid,布布扣,bubuko.com

WPF 动态布局Grid

标签:style   class   blog   code   http   tar   

原文地址:http://www.cnblogs.com/gaobing/p/3809594.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!