DataGrid WPF 中具有动态列的控件
我需要在表格单元格内放置一个堆栈面板,但如果我像这样执行逻辑......
DataGrid dg = new DataGrid();
StackPanel sp = new StackPanel();
sp.高度 = 18;
sp.宽度= 60;
sp.Orientation = Orientation.Horizontal;
按钮 btn = new Button();
btn.宽度 = 10;
btn.高度 = 10;
sp.Children.Add(btn);
标签 bt = new Label();
bt.Content = "测试";
bt.Margin = new Thickness(0, -3, 0, 0);
sp.Children.Add(bt);
DataTable dt = new DataTable();
DataColumn dc = new DataColumn("你好");
dt.Columns.Add(dc);
DataRow dr = dt.NewRow();
dr[0] = sp; dt.Rows.Add(dr);
dg.ItemsSource = dt.DefaultView;
l1.内容=dg;
它在单元格中显示“System.Windows.Controls.StackPanel”......如何在 GridView 单元格中获取 StackPanel(具有多个控件)
I need to put a stackpanel inside the table cell but if i did my logic like this....
DataGrid dg = new DataGrid();
StackPanel sp = new StackPanel();
sp.Height = 18;
sp.Width = 60;
sp.Orientation = Orientation.Horizontal;
Button btn = new Button();
btn.Width = 10;
btn.Height = 10;
sp.Children.Add(btn);
Label bt = new Label();
bt.Content = "test";
bt.Margin = new Thickness(0, -3, 0, 0);
sp.Children.Add(bt);
DataTable dt = new DataTable();
DataColumn dc = new DataColumn("hello");
dt.Columns.Add(dc);
DataRow dr = dt.NewRow();
dr[0] = sp; dt.Rows.Add(dr);
dg.ItemsSource = dt.DefaultView;
l1.Content = dg;
it is showing "System.Windows.Controls.StackPanel" in the cell..... how to get a StackPanel(with multiple Controls) in side the GridView cell
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该为网格单元创建自定义模板。请参阅此< /a>.
You should create custom template for your grid cells. See this.