This repository has been archived by the owner on Sep 19, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainWindow.xaml.cs
38 lines (36 loc) · 1.49 KB
/
MainWindow.xaml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
using DevExpress.Xpf.Spreadsheet;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
namespace CellTemplateSelectorExample
{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
spreadsheetControl1.LoadDocument("vlookup.xlsx");
#region #celltemplate_code
spreadsheetControl1.CellTemplateSelector = spreadsheetControl1.TryFindResource("CellTemplateSelector") as DataTemplateSelector;
#endregion #celltemplate_code
}
}
public class CellTemplateSelector : DataTemplateSelector
{
public override DataTemplate SelectTemplate(object item, DependencyObject container)
{
CellData data = item as CellData;
return CanApplyCustomTemplate(data.Cell.GetReferenceA1()) ? GetCellTemplate(data.Cell, (SpreadsheetControl)container) : base.SelectTemplate(item, container);
}
List<string> customTemplateCells = new List<string>() { "A2", "A3", "A4", "A5", "A6" };
private bool CanApplyCustomTemplate(string cellPosition)
{
return customTemplateCells.Contains(cellPosition);
}
private DataTemplate GetCellTemplate(DevExpress.Spreadsheet.Cell cell, SpreadsheetControl control)
{
string templateName = cell.HasFormula ? "FormulaTemplate" : "EmptyTemplate";
return control.TryFindResource(templateName) as DataTemplate;
}
}
}