以编程方式向gridview添加复选框C#

时间:2016-08-09 00:49:07

标签: c# wpf gridview avalondock

我需要在代码生成的gridview中添加一个复选框(以及其他控件)。我是新手编程并在WPF中构建一个没有任何数据绑定或MVVM的程序,我需要创建一个Avalon LayoutDocument的模板,其中gridview除了包含其他标准条目外还包含复选框列。其内容由其他AvalonDock Panes代码编辑。

以下是我要复制的XAML:

<xcad:LayoutDocument x:Name="layDocSubProjectTemplate" Title="SubProject1" CanClose="True">
 <Grid x:Name="TestGrid" >
  <Grid.RowDefinitions>
   <RowDefinition Height="*"/>
   <RowDefinition Height="*"/>
   <RowDefinition Height="*"/>
   <RowDefinition Height="*"/>
  </Grid.RowDefinitions>
  <Grid.ColumnDefinitions>
   <ColumnDefinition Width="20"/>
   <ColumnDefinition Width="*"/>
  </Grid.ColumnDefinitions>
  <ListView x:Name="lviewSubWalls"  Grid.Row="0" Grid.Column="1" Width="Auto" Grid.RowSpan="1">
   <ListView.View>
    <GridView>
     <GridView.Columns>
      <GridViewColumn>
       <GridViewColumn.CellTemplate>
        <DataTemplate>
         <CheckBox/>
        </DataTemplate>
       </GridViewColumn.CellTemplate>
      </GridViewColumn>
      <GridViewColumn Header="Name" Width="Auto"/>
      <GridViewColumn Header="Product" Width="Auto"/>
      <GridViewColumn Header="Colour" Width="Auto"/>
      <GridViewColumn Header="Sq' Face" Width="Auto"/>
      <GridViewColumn Header="Linear feet"  Width="Auto"/>
      <GridViewColumn Header="rows" Width="Auto"/>
      <GridViewColumn Header="Pallets/bundles" Width="Auto"/>
      <GridViewColumn Header="Hours" Width="Auto"/>
     </GridView.Columns>
    </GridView>
   </ListView.View>
  </ListView>
  <ListView x:Name="lviewSubPatio" Grid.Row="1" Grid.Column="1"          Width="AUto" Grid.RowSpan="1">
   <ListView.View>
    <GridView>
     <GridView.Columns>
      <GridViewColumn>
       <GridViewColumn.CellTemplate>
        <DataTemplate >
         <CheckBox Width="Auto"/>
        </DataTemplate>
       </GridViewColumn.CellTemplate>
      </GridViewColumn>
      <GridViewColumn Header="Name" Width="Auto"/>
      <GridViewColumn Header="Product" Width="Auto"/>
      <GridViewColumn Header="Colour"  Width="Auto"/>
      <GridViewColumn Header="Area" Width="Auto"/>
      <GridViewColumn Header="rows" Width="Auto"/>
      <GridViewColumn Header="Pallets/bundles" Width="Auto"/>
      <GridViewColumn Header="Hours" Width="Auto"/>
     </GridView.Columns>
    </GridView>
   </ListView.View>
  </ListView>
 </Grid>
</xcad:LayoutDocument>

这是用于创建具有相同结构的新LayoutDocument的click事件。

private void lblNewSubProject_MouseDown(object sender, MouseButtonEventArgs e)
{
 int count = MyLayoutDocumentPane.ChildrenCount;
 System.Diagnostics.Debug.WriteLine(count);
 Xceed.Wpf.AvalonDock.Layout.LayoutDocument newSub = new Xceed.Wpf.AvalonDock.Layout.LayoutDocument();
//When run only one of the existing LayoutDocuments has any content!!!
//Hence the need for some sort of template
newSub.Content = layDocSubProjectTemplate.Content;      
newSub.CanClose = true;
newSub.Title = "SubProject" + count;

}

我意识到MVVM对于这个很理想,但是我太过于重做我的程序(除非我可以通过MVVM做布局文档......这是可能的吗?)

0 个答案:

没有答案