Silverlight中用后台代码自定义Grid
通过后台代码来自定义一个Grid
//实例化一个Grid Grid grid = new Grid(); //设置RowDefinition RowDefinition row1 = new RowDefinition(); row1.Height = new GridLength(20); grid.RowDefinitions.Add(row1); RowDefinition row2 = new RowDefinition(); row2.Height = new GridLength(80); grid.RowDefinitions.Add(row2); Button b = new Button(); b.Height = 20; b.Width = 30; b.HorizontalAlignment = HorizontalAlignment.Right; b.Content = "关闭"; b.Click += b_Click; //将Button添加到Grid中 grid.Children.Add(b); //设置Button在Grid中的位置 b.SetValue(Grid.RowProperty, 0); TextBlock txt = new TextBlock(); txt.Text = "this is a test"; txt.Height = 80; txt.Width = 200; //将TextBlock添加到Grid中 grid.Children.Add(txt); //设置TextBlock在Grid中的位置 txt.SetValue(Grid.RowProperty, 1);
如果我的文章对你有帮助,就点一下推荐吧.(*^__^*)
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步