首页 > 其他 > 详细

WPF 动态布局Grid

时间:2014-06-27 19:40:08      阅读:486      评论:0      收藏:0      [点我收藏+]
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

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!