【问题标题】:Controls in DataGrid WPF with dynamic columnsDataGrid WPF 中带有动态列的控件
【发布时间】:2011-12-04 07:27:13
【问题描述】:

我需要在表格单元格中放置一个堆栈面板,但如果我这样做的话......

DataGrid dg = new DataGrid();

StackPanel sp = new StackPanel();

sp.Height = 18;

sp.Width = 60;

sp.Orientation = Orientation.Horizo​​ntal;

按钮 btn = new Button();

btn.Width = 10;

btn.Height = 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("hello");

dt.Columns.Add(dc);

DataRow dr = dt.NewRow();

博士[0] = sp; dt.Rows.Add(dr);

dg.ItemsSource = dt.DefaultView;

l1.Content = dg;

它在单元格中显示“System.Windows.Controls.StackPanel”.....如何在 GridView 单元格中获取 StackPanel(带有多个控件)

【问题讨论】:

    标签: datagrid datatable


    【解决方案1】:

    您应该为您的网格单元创建自定义模板。见this

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-02-24
      • 2011-03-05
      • 1970-01-01
      • 2015-08-01
      • 2012-04-24
      • 1970-01-01
      • 2014-12-15
      • 1970-01-01
      相关资源
      最近更新 更多