首页 > 编程语言 >WPF generate rows and columns via C# dynamically

WPF generate rows and columns via C# dynamically

时间:2024-07-14 19:20:55浏览次数:8  
标签:via C# dynamically System GridLength Windows using new 100

//xaml
<Window x:Class="WpfApp214.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:WpfApp214"
        mc:Ignorable="d"
        Title="MainWindow" Height="450" Width="800">
    <Grid x:Name="gd">
        
    </Grid>
</Window>


//cs
using System;
using System.Collections.Generic;
using System.Data.SqlTypes;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace WpfApp214
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            Loaded += MainWindow_Loaded;
        }

        private void MainWindow_Loaded(object sender, RoutedEventArgs e)
        {
            this.WindowState = WindowState.Maximized;
            RowDefinition[] rows =
            {
                new RowDefinition{Height=new GridLength(100)},
                new RowDefinition{Height=new GridLength(100)},
                new RowDefinition{Height=new GridLength(100)},
                new RowDefinition{Height=new GridLength(100)},
                new RowDefinition{Height=GridLength.Auto },
                new RowDefinition{Height=new GridLength(2,GridUnitType.Star) }
            };

            ColumnDefinition[] columns =
            {
                new ColumnDefinition{Width=new GridLength(100)},
                new ColumnDefinition{Width=new GridLength(100)},
                new ColumnDefinition{Width=new GridLength(100)},
                new ColumnDefinition{Width=new GridLength(100)},
                new ColumnDefinition{Width=new GridLength(100)},
                new ColumnDefinition{Width=GridLength.Auto},
                new ColumnDefinition{Width=new GridLength(2,GridUnitType.Star)}
            };
            Array.ForEach(rows,row=>gd.RowDefinitions.Add(row));
            Array.ForEach(columns,col=>gd.ColumnDefinitions.Add(col));
            gd.ShowGridLines = true;
        }
    }
}

 

 

 

 

 

标签:via,C#,dynamically,System,GridLength,Windows,using,new,100
From: https://www.cnblogs.com/Fred1987/p/18301888

相关文章

  • SMU Summer 2024 Contest Round 3(7.10)zhaosang
    打的最菜一次,最惨一次,题读假了A-Ahttp://162.14.124.219/contest/1007/problem/A签到题要解决这道题,素数对,数据量不是很大,所以我们可以先预处理素数,这个偶数肯定是等于小于它的两个素数,所以只需要遍历到小于它即可,把素数存起来,然后这两个素数的和等于这个偶数,并且要求相差最小......
  • C++惯用法:do...while(0)的妙用
    目录1.引言2.do...while(0)消除goto语句3.用do...while(0)包裹复杂的宏4.防止意外错误5.避免变量作用域问题1.引言        在C++中,do...while(0) 通常是用来做循环用的,然而我们做循环操作可能用for和while要多一些。经常看到一些开源代码会出现do...while(0)......
  • Cocos 打包微信小游戏,关闭load插屏
    最近开始研究微信小游戏,有兴趣的可以关注一下公众号,记录一些心路历程和源代码。一共有2个load如图下这个在构建小程序项目之后我们打开 first-screen.js 找到 tick方法里的 draw注释掉运行微信小游戏就没有那个load了。在构建发布时可以选择不勾选或者更......
  • 网站源码SEO公司pbootcms模板网页设计主题
    SEO公司的网站设计分享我很高兴向大家介绍我刚刚制作的SEO公司的网站设计。友好的站点界面,是打动访客的第一步。SEO公司网站主题网站设计旨在展示公司的专业能力、服务范围以及优化效果,吸引潜在客户的关注,提升公司在搜索引擎中的排名和可见性。以下是对SEO公司网站主题设计的......
  • Science Advances|用于肌电检测的柔性微针电极阵列(健康监测/柔性传感/柔性电子)
    2024年5月1日,美国南加州大学HangboZhao课题组在《ScienceAdvances》上发布了一篇题为“Highlystretchableandcustomizablemicroneedleelectrodearraysforintramuscularelectromyography”的论文。论文内容如下:一、摘要        可伸缩的三维穿透式微电极......
  • [CTSC2018] 混合果汁
    先考虑如何处理单个询问,看到了最大值最小,不难想到二分但是为了整体二分的方便,这个check函数必须这么写:先将果汁以美味度排序,然后以价格为下标建立树状数组,将美味度不低于\(mid\)的果汁扔进树状数组里面(注意有两个树状数组,一个用来几率体积,另一个用来记录体积乘以价格),然后再二分价......
  • 张传波老师Scrum学习心得
    用户故事是一个用来确认用户和用户需求的简短描述,它从用户的角度来描述用户渴望得到的功能。一个好的用户故事通常包括三个要素:1.角色:谁要使用这个功能;2.活动:需要完成什么样的功能;3.商业价值:为什么需要这个功能,这个功能带来什么样的价值。用户故事通常按照如下格式来表达:......
  • gRPC 高级——Validator 验证器
    gRPC验证器(Validator)是一种用于在gRPC通信过程中进行数据验证的工具,通过在.proto文件中定义验证规则(例如长度限制、格式检查等),确保客户端和服务器之间传递的数据符合预期的格式和约束条件。它使用ProtocolBuffers作为序列化机制,并通过生成的代码在传输过程中自动执......
  • 2024/7/13 ABC362 比赛记录
    7/14:昨晚打的abc,外面下着大雨;1650ptsrank975T1:简单签到题,愣是被我拖了7min死因:开赛时老师开始收手机,一直叫我名,我一着急装了两个翻译插件,导致页面错版。时间宝贵,于是我艰难的对照样例勉强读懂题(T2:计算几何?给平面直角坐标系3点,判rt三角形。直接double勾股定理算边......
  • Reinforced Causal Explainer for GNN论文笔记
    论文:TPAMI2023 图神经网络的强化因果解释器论文代码地址:代码目录AbstractIntroductionPRELIMINARIESCausalAttributionofaHolisticSubgraph​individualcausaleffect(ICE)​*CausalScreeningofanEdgeSequenceReinforcedCausalExplainer(RC-Explaine......