0

I need to add a checkbox (among other controls) to a gridview generated by code. I am new to programming and built a program in WPF without any databinding or MVVM and I need to create a template of an Avalon LayoutDocument with a gridview that contains a checkbox column in addition to other standard entries. The contents of which are edited by code other AvalonDock Panes.

The following is the XAML that I want to replicate:

<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>

And this is the click event to create a new LayoutDocument with the same structure.

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;

}

I realize MVVM would be ideal for this but I am too far along to redo my program (unless I can just do the layoutdocuments via MVVM... is that a possibility?)

vivek kv
  • 406
  • 6
  • 11
ToucanSamIAm
  • 99
  • 1
  • 5
  • Just use the XAML. Why can't you? – 15ee8f99-57ff-4f92-890c-b56153 Aug 09 '16 at 02:02
  • That would be awesome if I can but I'm not sure how I would edit the XAML during runtime... I need to create a new and distinguishable instance of the LayoutDocument "layDocSubProjectTemplate" in a DocumentPane on a button_click event and I am not aware of any way to do that through XAML. – ToucanSamIAm Aug 09 '16 at 04:02
  • _"I am new to programming and built a program in WPF without any databinding"_ -- I know it doesn't seem like it now, but trust me and anyone else who tells you the same: you will find it easier in the long run if you just take the time now to learn the normal WPF idioms, which rely heavily on data binding and the basic concepts behind the MVVM pattern, if not their literal prescriptions. However far along you are, fact is you are fighting an uphill battle. You're better off starting over than continuing the fight. – Peter Duniho Aug 09 '16 at 04:20
  • 1
    _"I'm not sure how I would edit the XAML during runtime"_ -- you let WPF do it for you. By changing the view model or even what view model you are using, you cause WPF to modify the XAML implicitly, through templates, triggers found in styles, etc. To explain the whole process here (even in an answer) would be too broad. But: first, think about the changeable values represented by your UI...these are the properties of your view model; then second, think about what XAML is required to represent these value...this would be the template for your view model. – Peter Duniho Aug 09 '16 at 04:24

0 Answers0