Skip to content

Releases: cuikp/AvRichTextBox

Experimenting with table support

31 Jan 05:18

Choose a tag to compare

Pre-release

I'm thinking that representing a table as an EditableTable that inherits from Grid makes most sense. Binding that to a Table object which inherits Block allows it to be inserted into the FlowDocument in the same way as a Paragraph.
So:
EditableParagraph -> SelectableTextBlock
EditableTable -> Grid

Then Grid children would be a collection of EditableCell (inherting from Border), bound to collection of Cell, and each containing an EditableParagraph so it can hold text.

So the DataTemplate for a Table becomes something like:

<DataTemplate DataType="local:Table" >  

	<Border BorderBrush="Black" BorderThickness="{Binding BorderThickness}" Margin="{Binding Margin}" HorizontalAlignment="{Binding TableAlignment}" Width="{Binding Width}" Height="{Binding Height}" >
											
	<local:EditableTable Background="GhostWhite" >
		<ItemsControl ItemsSource="{Binding Cells}">

		<ItemsControl.ItemsPanel>  
			<ItemsPanelTemplate>  
  		        <local:BindableGrid RowDefs="{Binding RowDefs}" ColDefs="{Binding ColDefs}"/>  
 	           </ItemsPanelTemplate>  
  	         </ItemsControl.ItemsPanel>  
			<ItemsControl.Styles>  
			<Style Selector="ItemsControl > ContentPresenter">
			        <Setter Property="Grid.Row" Value="{Binding RowNo}" />
				  <Setter Property="Grid.Column" Value="{Binding ColNo}" />
			</Style>
			 </ItemsControl.Styles>


			  <ItemsControl.ItemTemplate>
			     <DataTemplate x:DataType="{x:Type local:Cell}">
				 <local:EditableCell    Grid.Row="{Binding RowNo}"    Grid.Column="{Binding ColNo}" BorderThickness="{Binding BorderThickness}" BorderBrush="{Binding BorderBrush}">
			              <local:EditableParagraph DataContext="{Binding CellContent}" />  
				 </local:EditableCell>
		           </DataTemplate>
   	                  </ItemsControl.ItemTemplate>
 	      </ItemsControl>
	</local:EditableTable>
</Border>
</DataTemplate>
									

Actually, stepping back and looking at this, probably EditableTable can inherit ItemsControl instead of Grid, since the internal ItemsControl.ItemsPanel is the Grid that arranges the Cells. Then the enclosing Border can also be dispensed with since ItemsControl already has a Border.

Navigation across the Table will have to jump cell-to-cell to the EditableParagraph in each EditableCell.