public override DataTemplate SelectTemplate(object item, DependencyObject container) { if (item is CellTemplateDemoClass) { CellTemplateDemoClass democlass = item as CellTemplateDemoClass; if (democlass.Value1 > 2) { return(this.FirstTemplate); } else { return(this.SecondTemplate); } } return(null); }
public CellTemplateVm() { this.RowHeaders = new[] { "R1", "R2", "R3" }; this.ColumnHeaders = new[] { "C1", "C2", "C3" }; this.cellTemplate1 = CreateCellTemplate("Value1"); this.cellTemplate2 = CreateCellTemplate("Value2"); this.cellEditingTemplate1 = CreateCellEditingTemplate("Value1"); this.cellEditingTemplate2 = CreateCellEditingTemplate("Value2"); this.myCellTemplate = this.cellTemplate1; this.myCellEditingTemplate = this.cellEditingTemplate1; this.Data2D = new CellTemplateDemoClass[3, 3]; var r = new Random(); for (var i = 0; i < 3; ++i) { for (var j = 0; j < 3; ++j) { var cl = new CellTemplateDemoClass { Value1 = i + j, Value2 = 9 - j - i, Background = new SolidColorBrush(new Color { A = (byte)r.Next(255), R = (byte)r.Next(255), G = (byte)r.Next(255), B = (byte)r.Next(255), }), }; this.Data2D[i, j] = cl; } } this.ChangeCellTemplateCommand = new RelayCommand(this.ChangeCellTemplate); }
public CellTemplateVm() { this.RowHeaders = new[] { "1", "2", "3" }; this.ColumnHeaders = new[] { "C1", "C2", "C3" }; this.celltemplate1 = this.CreateCellTemplate("Value1"); this.celltemplate2 = this.CreateCellTemplate("Value2"); this.celleditingtemplate1 = this.CreateCellEditingTemplate("Value1"); this.celleditingtemplate2 = this.CreateCellEditingTemplate("Value2"); this.MyCellTemplate = this.celltemplate1; this.MyCellEditingTemplate = this.celleditingtemplate1; this.Data2D = new CellTemplateDemoClass[3, 3]; Random r = new Random(); for (int i = 0; i < 3; ++i) { for (int j = 0; j < 3; ++j) { CellTemplateDemoClass cl = new CellTemplateDemoClass(); cl.Value1 = i + j; cl.Value2 = 9 - j - i; cl.Background = new SolidColorBrush(new Color() { A = (byte)r.Next(255), R = (byte)r.Next(255), G = (byte)r.Next(255), B = (byte)r.Next(255) }); this.Data2D[i, j] = cl; } } this.ChangeCellTemplateCommand = new RelayCommand(this.ChangeCellTemplate); }