Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/guorg/gu.wpf.datagrid2d

Extension methods for WPF DataGrid enabling binding to T[,]
https://github.com/guorg/gu.wpf.datagrid2d

attached-properties datagrid wpf

Last synced: about 2 hours ago
JSON representation

Extension methods for WPF DataGrid enabling binding to T[,]

Awesome Lists containing this project

README

        

# Gu.Wpf.DataGrid2D

[![Gitter Chat Room](https://img.shields.io/gitter/room/nwjs/nw.js.svg)](https://gitter.im/JohanLarsson/Gu.Wpf.DataGrid2D?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
[![License](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
[![NuGet](https://img.shields.io/nuget/v/Gu.Wpf.DataGrid2D.svg)](https://www.nuget.org/packages/Gu.Wpf.DataGrid2D/)
[![ci](https://github.com/GuOrg/Gu.Wpf.DataGrid2D/actions/workflows/ci.yml/badge.svg)](https://github.com/GuOrg/Gu.Wpf.DataGrid2D/actions/workflows/ci.yml)

Attached properties for WPF DataGrid enabling binding to sources of different types. For using `DataGrid2D` you need to add `xmlns:dataGrid2D="http://gu.se/DataGrid2D"` in XAML

## Contents

- [ItemsSource.Array2D & Array2DTransposed](#itemssourcearray2d--array2dtransposed)
- [Array2D](#array2d)
- [Explicit columns](#explicit-columns)
- [With headers:](#with-headers)
- [Array2DTransposed](#array2dtransposed)
- [ItemsSource.RowsSource & ColumnsSource](#itemssourcerowssource--columnssource)
- [RowsSource](#rowssource)
- [ColumnsSource](#columnssource)
- [Different lengths](#different-lengths)
- [Selected.CellItem & Index](#selectedcellitem--index)
- [ItemsSource.TransposedSource & PropertySource](#itemssourcetransposedsource--propertysource)
- [PropertySource](#propertysource)
- [TransposedSource with explicit columns](#transposedsource-with-explicit-columns)
- [Rownumbers](#rownumbers)

## ItemsSource.Array2D & Array2DTransposed
For binding to sources of type T[,]

### Array2D
```xml

```
Renders:
![ItemsSource2D render](http://i.imgur.com/00325df.png)

### Explicit columns
Columns are referred to by `C`

```xml





```
Renders:
![ItemsSource2D render](http://i.imgur.com/IHvEI0c.png)

### With headers:
```xml

```
Renders:
![With headers screenie](http://i.imgur.com/GtEOW5G.png)

### Array2DTransposed
```xml

```
Renders:
![ItemsSource2D render](http://i.imgur.com/N6BJqIR.png)

## ItemsSource.RowsSource & ColumnsSource
Lets you bind to datasources of type `IEnumerable>`.
Tracks collection changes.

### RowsSource
```xml

```

Renders:
![ItemsSource2D render](http://i.imgur.com/00325df.png)

### ColumnsSource
```xml

```
Renders:
![ItemsSource2D render](http://i.imgur.com/N6BJqIR.png)

### Different lengths
Limited support for different lengths. Columns with blanks are default readonly.

```xml

```

Renders:
![ItemsSource2D render](http://i.imgur.com/PPlT750.png)

## Selected.CellItem & Index
Lets you two-way bind the item of the currently selected cell or index (row, col).
For this to work these conditions must be satisfied:
- `SelectionUnit="Cell"`
- Columns must be of type `DataGridBoundColumn`. Don't think there is a way to dig out the bound property of a `DataGridTemplateColumn`
```xml

```

## ItemsSource.TransposedSource & PropertySource
Support for transposing an itemssource, perhaps useful for property grid scenarios. Supports binding to single item or (Observable)Collection

### PropertySource
Same as TransposedSource but for a single item.

Renders:
![ItemsSource2D render](http://i.imgur.com/sn8VNKG.png)

### TransposedSource with explicit columns
The property name column is named `Name` and the following columns are named `C`
```xml





```

Renders:
![ItemsSource2D render](http://i.imgur.com/ftkeyDu.png)

## Rownumbers
Convenience attached property if you want to display rownumbers.
Specify the number to start fom using `StartAt`
```xml



<Setter Property="Content" Value="{Binding Path=(dataGrid2D:Index.OfRow), RelativeSource={RelativeSource AncestorType={x:Type DataGridRow}}}" />

```
Renders:
![Rownumbers render](http://i.imgur.com/VkDap9E.png)