首页 > 代码库 > WPF 动态布局Grid
WPF 动态布局Grid
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);
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。