【问题标题】:Create Static Header with Dynamic Empty Editable Rows in WPF在 WPF 中创建具有动态空可编辑行的静态标题
【发布时间】:2021-04-23 02:42:39
【问题描述】:

任何人都知道如何在 WPF 程序中创建带有标题表的动态行。 我能够创建带有标题的动态行,但不幸的是这些行无法编辑。 (附截图)

xaml(源代码)

   <DataGrid Name = "dataGrid" CanUserAddRows="True" AutoGenerateColumns = "False" Grid.Column="0" Grid.Row="2">

        <DataGrid.Columns>
            <DataGridTextColumn Header = "NUMBER   " Binding = "{Binding Path=ID}" />
            <DataGridTextColumn Header = "STAGE ID  " Binding = "{Binding Path=StageID}" />
            <DataGridTextColumn Header = "STAGE DESCRIPTION   " Binding = "{Binding Path=StageDescription}"/>
        </DataGrid.Columns>

    </DataGrid>

cs(源代码)

    for (int i = 1; i <= 4; ++i)
    {  
        dataGrid.Items.Add(new Stage());
    }

  public class Stage
  {
      public string ID { get; set; }
      public string StageID { get; set; }
      public string StageDescription { get; set; }
  }

表格

【问题讨论】:

    标签: c# .net wpf


    【解决方案1】:
    private readonly ObservableCollection<Stage> stages
         = new ObservableCollection<Stage>();
    
     public СonstructorWindow()
     {
        InitializeComponent();
        dataGrid.ItemsSource = stages;
     }
    
     void SomeMethod()
     { 
        for (int i = 0; i < 4; i++)
        {  
           srages.Add(new Stage());
        }
     }
    

    【讨论】:

      猜你喜欢
      • 2015-07-28
      • 1970-01-01
      • 1970-01-01
      • 2014-01-17
      • 2017-12-11
      • 1970-01-01
      • 1970-01-01
      • 2011-08-23
      • 2023-03-19
      相关资源
      最近更新 更多