I was wondering if there is a way (any components/controls) that allow me to draw a simple Microsoft Word style table in my application window. Something like this:
Any ideas?
Declaring a DataGrid in XAMLCanUserResizeColumns – allows the user to change the width of columns in the table. CanUserSortColumns – allows the user to sort the data in the table by clicking on column names. IsReadOnly – when true, prevents the user from double-clicking a cell to edit its contents.
Advertisements. A DataGrid is a control that displays data in a customizable grid. It provides a flexible way to display a collection of data in rows and columns.
RowDefinitions. Add(gridRow3); Once rows and columns are added to Grid, you can add any contents to Grid cells by using SetRow and SetColumn methods. SetRow and SetColumn methods take first parameter as the control name and second parameter as row number and column number respectively.
As said in the comments, you can use Telerik Grid. However, if you want to build the table yourself the Grid control will suffice. This will create, respectively, a column that sizes itself based on the amount of available space and a row that sizes itself to its content.
It depends on how you want to use it. Either use one of the ItemsControl
(like DataGrid
, ListView
etc), do it directly with a Grid
panel (as recommended by the other answers) or use a FlowDocument
FlowDocument
allows you to specify Tables, Rows and Columns. You can also select several cells at once for Copy/Paste etc.
<FlowDocumentReader UseLayoutRounding="True" SnapsToDevicePixels="True">
<FlowDocumentReader.Resources>
<Style TargetType="TableCell">
<Setter Property="TextAlignment" Value="Center"/>
</Style>
</FlowDocumentReader.Resources>
<FlowDocument>
<Table CellSpacing="0">
<Table.Columns>
<TableColumn/>
<TableColumn/>
<TableColumn/>
<TableColumn/>
</Table.Columns>
<TableRowGroup>
<TableRow>
<TableCell BorderBrush="Black" BorderThickness="1">
<Paragraph FontWeight="Bold">Category</Paragraph>
</TableCell>
<TableCell BorderBrush="Black" BorderThickness="0,1,1,1">
<Paragraph FontWeight="Bold">A</Paragraph>
</TableCell>
<TableCell BorderBrush="Black" BorderThickness="0,1,1,1">
<Paragraph FontWeight="Bold">B</Paragraph>
</TableCell>
<TableCell BorderBrush="Black" BorderThickness="0,1,1,1">
<Paragraph FontWeight="Bold">C</Paragraph>
</TableCell>
</TableRow>
<TableRow>
<TableCell BorderBrush="Black" BorderThickness="1,0,1,1">
<Paragraph FontWeight="Bold">Subscription</Paragraph>
</TableCell>
<TableCell BorderBrush="Black" BorderThickness="0,0,1,1">
<Paragraph>Monthly</Paragraph>
</TableCell>
<TableCell BorderBrush="Black" BorderThickness="0,0,1,1">
<Paragraph>Yearly</Paragraph>
</TableCell>
<TableCell BorderBrush="Black" BorderThickness="0,0,1,1">
<Paragraph>Monthly</Paragraph>
</TableCell>
</TableRow>
<TableRow>
<TableCell BorderBrush="Black" BorderThickness="1,0,1,1" TextAlignment="Center">
<Paragraph FontWeight="Bold">Price</Paragraph>
</TableCell>
<TableCell BorderBrush="Black" BorderThickness="0,0,1,1">
<Paragraph>$120.00</Paragraph>
</TableCell>
<TableCell BorderBrush="Black" BorderThickness="0,0,1,1">
<Paragraph>$1000.00</Paragraph>
</TableCell>
<TableCell BorderBrush="Black" BorderThickness="0,0,1,1">
<Paragraph>$130.00</Paragraph>
</TableCell>
</TableRow>
</TableRowGroup>
</Table>
</FlowDocument>
</FlowDocumentReader>
This page is full of usefull examples about this: FlowDocument with Table
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With