This is a migrated thread and some comments may be shown as answers.

Rounded Cell Corners

2 Answers 334 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Scott Michetti
Top achievements
Rank 1
Iron
Scott Michetti asked on 09 Oct 2013, 07:14 PM
Hello, I was looking at this post http://www.telerik.com/community/forums/wpf/gridview/rounded-corners.aspx, and I was wondering if I could do the rounding at the cell level. I'm creating columns dynamically, so I don't know how to do a cell template. I was thinking of just adding a textbox with rounded corners as the cell template and remove the gridlines to get this effect, but adding columns dynamically prevents this I believe. I would like all cells in the grid to have the rounded corners.

Thanks,
Scott

2 Answers, 1 is accepted

Sort by
0
Ivan Ivanov
Telerik team
answered on 11 Oct 2013, 12:35 PM
Hi,

 Something like this should do the trick:

GridViewDataColumn dc = new GridViewDataColumn();
dc.DataMemberBinding = new Binding("Name");
FrameworkElementFactory feTb = new FrameworkElementFactory(typeof(TextBlock));
FrameworkElementFactory feB = new FrameworkElementFactory(typeof(Border));
feB.SetValue(Border.PaddingProperty, new Thickness(3));
feB.SetValue(Border.CornerRadiusProperty, new CornerRadius(3));
feB.SetValue(Border.BorderBrushProperty, new SolidColorBrush(Colors.Black));
feB.SetValue(Border.BorderThicknessProperty, new Thickness(1));
feB.AppendChild(feTb);
feTb.SetBinding(TextBlock.TextProperty, new Binding("Name"));          
DataTemplate dt = new DataTemplate();
dt.VisualTree = feB;
dt.Seal();
dc.CellTemplate = dt;
clubsGrid.Columns.Add(dc);

Regards,
Ivan Ivanov
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
Scott Michetti
Top achievements
Rank 1
Iron
answered on 11 Oct 2013, 03:46 PM
Thanks Ivan, that works great. I placed your code in the AutoGeneratingColumn event to get this to work on all columns. I just changed your first line to GridViewDataColumn dc = e.Column as GridViewDataColumn; and gave each column a unique name.

Thanks,
Scott
Tags
GridView
Asked by
Scott Michetti
Top achievements
Rank 1
Iron
Answers by
Ivan Ivanov
Telerik team
Scott Michetti
Top achievements
Rank 1
Iron
Share this question
or