-
Notifications
You must be signed in to change notification settings - Fork 1k
/
Copy pathHightlightColumn.cs
65 lines (59 loc) · 2.49 KB
/
HightlightColumn.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using Telerik.Windows.Controls;
using Telerik.Windows.Controls.GridView;
namespace HighlightCustomColumn
{
class HightlightColumn : GridViewBoundColumnBase
{
public override System.Windows.FrameworkElement CreateCellElement(Telerik.Windows.Controls.GridView.GridViewCell cell, object dataItem)
{
StackPanel mainContainer = new StackPanel();
mainContainer.Orientation = Orientation.Horizontal;
//Add an additional element in the cell
if (cell.DataContext != null)
{
Image image = new Image();
image.Source = new BitmapImage(new Uri(string.Format("/Images/{0}.png", (cell.DataContext as Club).Name), UriKind.RelativeOrAbsolute));
mainContainer.Children.Add(image);
}
//Add HighlightTextBlock to keep the SearchPanel functionality
HighlightTextBlock htb = new HighlightTextBlock(this.DataControl.SearchStateManager);
htb.DataType = this.DataType;
htb.SetBinding(HighlightTextBlock.HighlightTextProperty, new Binding(this.DataMemberBinding.Path.Path));
cell.SetBinding(GridViewCell.IsHighlightedProperty, new Binding("ContainsMatch") { Source = htb, Mode = BindingMode.TwoWay });
SetHighlightTextBlockTextProperty(dataItem, htb);
mainContainer.Children.Add(htb);
return mainContainer;
}
public void SetHighlightTextBlockTextProperty(object dataItem, TextBlock textBlock)
{
if (this.DataMemberBinding != null)
{
var content = this.GetCellContent(dataItem);
if (content != null)
{
textBlock.SetValue(TextBlock.TextProperty, string.Format("{0}", content));
}
}
else
{
textBlock.ClearValue(TextBlock.TextProperty);
}
}
public override System.Windows.FrameworkElement CreateCellEditElement(GridViewCell cell, object dataItem)
{
var textbox = new TextBox();
textbox.SetBinding(TextBox.TextProperty, new Binding(this.DataMemberBinding.Path.Path));
return textbox;
}
}
}