This page assumes unvell.ReoGrid.One.Wpf is already installed (Installation).
The APIs for reading and writing cells, formulas and styles live in the core, so they are shared with the WinForms edition. This page focuses on placing the control. For how to set values, see Getting started with WinForms.
Placing the control in XAML
The control lives in the unvell.ReoGrid.Wpf namespace; the assembly is unvell.ReoGrid.One.Wpf.
<Window x:Class="MyApp.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:rg="clr-namespace:unvell.ReoGrid.Wpf;assembly=unvell.ReoGrid.One.Wpf"
Title="ReoGrid One" Width="900" Height="600">
<Grid>
<rg:ReoGridControl x:Name="grid" />
</Grid>
</Window>
After InitializeComponent() in the code-behind, set values on grid.ActiveWorksheet.
The sheet-building part looks like this.
using unvell.ReoGrid.Core;
using unvell.ReoGrid.Core.Style;
internal static class SheetBuilder
{
public static void BuildSheet(Worksheet sheet)
{
sheet.SetText(0, 0, "商品");
sheet.SetText(0, 1, "単価");
sheet.SetNumber(1, 1, 320);
sheet.SetFormula(2, 1, "SUM(B2:B2)");
sheet.SetRowStyle(0, new StyleRecord { Bold = true, BackgroundColor = 0xFFEFEFEF });
}
}
Call SheetBuilder.BuildSheet(grid.ActiveWorksheet) from the MainWindow constructor.
Reading and writing cells is a core API, so from here on everything is exactly the same
as the WinForms edition.
The .csproj settings:
<PropertyGroup>
<TargetFramework>net10.0-windows</TargetFramework>
<UseWPF>true</UseWPF>
</PropertyGroup>
Differences from the WinForms edition
No DPI conversion in the coordinate system
WPF logical units (DIPs) are based on 96 DPI, which matches the core’s coordinate system.
The DpiScale handling found in the WinForms edition is therefore unnecessary; per-monitor
DPI is handled by the framework.
Derives from Panel
ReoGridControl derives from Panel. The grid itself is drawn in OnRender; the scroll
bars, cell editor and dropdowns sit on top of it as child elements.
Printing is built in
Calling Print() hands the document to the print dialog through a DocumentPaginator.
using unvell.ReoGrid.Core.Printing;
grid.Print(); // 既定の設定で印刷
grid.Print(new PrintSettings { /* 用紙・余白・倍率など */ });
Main members
Same names and meanings as the WinForms edition.
| Operation | Members |
|---|---|
| Workbook / active sheet | Workbook, ActiveWorksheet, SetWorksheet(ws) |
| Selection | Selection, ActiveCell, SelectionChanged |
| Undo / redo | Undo(), Redo(), CanUndo, CanRedo, HistoryChanged |
| Zoom | Zoom, ZoomChanged |
| Freeze panes | SetFreeze(rows, cols) |
| Loading | LoadWorkbook(wb), NewWorkbook(), LoadJson(json) |
| Printing | Print(settings) |
Japanese input
IME input is supported. When you start typing Japanese in a cell that is not in edit mode, the editor opens in place and input continues there (the same behavior as the WinForms edition).
Read next
- Applying a license key
- Getting started with Avalonia — if you also target Linux / macOS