WPF Grid 的自适应布局

更新日期: 2022-10-22 阅读次数: 1777 字数: 151 分类: Windows

一个不错的教程

图文并茂

https://www.c-sharpcorner.com/UploadFile/1e050f/grid-layout-in-wpf/

比官方文档好太多了。看上去作者像是印度人,这种文章能有 52 万的阅读量,确实非常惊人。

代码创建 Grid

https://learn.microsoft.com/en-us/dotnet/desktop/wpf/controls/how-to-create-a-grid-element?view=netframeworkdesktop-4.8

没想到用 CSharp 代码实现 Grid 看起来可读性也不错。对于动态显示的使用场景,可能比 XAML 更灵活。

// Create the application's main window
mainWindow = new Window();
mainWindow.Title = "Grid Sample";

// Create the Grid
Grid myGrid = new Grid();
myGrid.Width = 250;
myGrid.Height = 100;
// ...

// Add the Grid as the Content of the Parent Window Object
mainWindow.Content = myGrid;
mainWindow.Show ();

tags: wpf

关于作者 🌱

我是来自山东烟台的一名开发者,有敢兴趣的话题,或者软件开发需求,欢迎加微信 zhongwei 聊聊, 查看更多联系方式