3 Answers, 1 is accepted
0
Hello YoungKee,
Your custom control should simply inherit from RadGridView and you will additionally need to predefine its control template, basing the style on the default RadGridView style, following the approach described here. For your convenience, I've prepared the following style:
This will enable Insert, and Remove functionality through the buttons in the stack panel. Of course, you can bind any available command RadGridView exposes.
I hope you find this helpful.
Regards,
Dilyan Traykov
Telerik
Your custom control should simply inherit from RadGridView and you will additionally need to predefine its control template, basing the style on the default RadGridView style, following the approach described here. For your convenience, I've prepared the following style:
<
Style
TargetType
=
"local:CustomRadGrid"
BasedOn
=
"{StaticResource RadGridViewStyle}"
>
<
Setter
Property
=
"Template"
>
<
Setter.Value
>
<
ControlTemplate
TargetType
=
"local:CustomRadGrid"
>
<
Grid
>
<
Grid.ColumnDefinitions
>
<
ColumnDefinition
/>
<
ColumnDefinition
Width
=
"0"
/>
<
ColumnDefinition
Width
=
"Auto"
/>
</
Grid.ColumnDefinitions
>
<
Grid.RowDefinitions
>
<
RowDefinition
Height
=
"Auto"
/>
<
RowDefinition
Height
=
"Auto"
/>
<
RowDefinition
Height
=
"Auto"
/>
<
RowDefinition
/>
<
RowDefinition
Height
=
"Auto"
/>
</
Grid.RowDefinitions
>
<
StackPanel
Orientation
=
"Horizontal"
>
<
Button
Content
=
"Add"
Command
=
"controls:RadGridViewCommands.BeginInsert"
/>
<
Button
Content
=
"Edit"
Command
=
"controls:RadGridViewCommands.BeginEdit"
/>
<
Button
Content
=
"Delete"
Command
=
"controls:RadGridViewCommands.Delete"
/>
</
StackPanel
>
<
telerik:GridViewSearchPanel
x:Name
=
"PART_SearchPanel"
Background
=
"{TemplateBinding SearchPanelBackground}"
Grid.ColumnSpan
=
"3"
Foreground
=
"{TemplateBinding SearchPanelForeground}"
Grid.Row
=
"1"
IsTabStop
=
"False"
>
<
telerik:GridViewSearchPanel.Visibility
>
<
Binding
Path
=
"ShowSearchPanel"
RelativeSource
=
"{RelativeSource TemplatedParent}"
>
<
Binding.Converter
>
<
telerik:BooleanToVisibilityConverter
/>
</
Binding.Converter
>
</
Binding
>
</
telerik:GridViewSearchPanel.Visibility
>
</
telerik:GridViewSearchPanel
>
<
telerik:GridViewGroupPanel
x:Name
=
"PART_GroupPanel"
Background
=
"{TemplateBinding GroupPanelBackground}"
Grid.ColumnSpan
=
"3"
Foreground
=
"{TemplateBinding GroupPanelForeground}"
IsTabStop
=
"False"
Grid.Row
=
"2"
/>
<
Border
x:Name
=
"PART_MasterGridContainer"
BorderBrush
=
"{TemplateBinding BorderBrush}"
BorderThickness
=
"{TemplateBinding BorderThickness}"
Background
=
"{TemplateBinding Background}"
Grid.ColumnSpan
=
"3"
Margin
=
"0,-1,0,0"
Padding
=
"{TemplateBinding Padding}"
Grid.Row
=
"2"
/>
<
ItemsControl
x:Name
=
"PART_ControlPanelItemsControl"
Grid.Column
=
"2"
HorizontalAlignment
=
"Right"
Grid.Row
=
"1"
>
<
ItemsControl.ItemsPanel
>
<
ItemsPanelTemplate
>
<
StackPanel
IsItemsHost
=
"True"
Orientation
=
"Horizontal"
/>
</
ItemsPanelTemplate
>
</
ItemsControl.ItemsPanel
>
<
ItemsControl.ItemTemplate
>
<
DataTemplate
>
<
telerik:ControlPanelItemControl
/>
</
DataTemplate
>
</
ItemsControl.ItemTemplate
>
</
ItemsControl
>
<
telerik:GridViewScrollViewer
x:Name
=
"PART_ItemsScrollViewer"
CanContentScroll
=
"True"
Grid.ColumnSpan
=
"3"
Margin
=
"1,0,1,1"
Grid.Row
=
"3"
Grid.RowSpan
=
"2"
>
<
telerik:GridViewScrollViewer.FooterRow
>
<
telerik:GridViewFooterRow
x:Name
=
"PART_FooterRow"
IsTabStop
=
"False"
IndentLevel
=
"{TemplateBinding GroupCount}"
/>
</
telerik:GridViewScrollViewer.FooterRow
>
<
telerik:GridViewScrollViewer.HeaderRow
>
<
telerik:GridViewHeaderRow
x:Name
=
"PART_HeaderRow"
IsTabStop
=
"False"
IndentLevel
=
"{TemplateBinding GroupCount}"
/>
</
telerik:GridViewScrollViewer.HeaderRow
>
<
telerik:GridViewScrollViewer.NewRow
>
<
telerik:GridViewNewRow
x:Name
=
"PART_AddNewRow"
IsTabStop
=
"False"
IndentLevel
=
"{TemplateBinding GroupCount}"
/>
</
telerik:GridViewScrollViewer.NewRow
>
<
telerik:GridViewVirtualizingPanel
x:Name
=
"PART_GridViewVirtualizingPanel"
CanHorizontallyScroll
=
"True"
CanVerticallyScroll
=
"True"
/>
</
telerik:GridViewScrollViewer
>
<
telerik:ScrollPositionIndicator
x:Name
=
"PART_ScrollPositionIndicator"
Grid.ColumnSpan
=
"3"
ContentTemplate
=
"{TemplateBinding ScrollPositionIndicatorTemplate}"
HorizontalAlignment
=
"Right"
IsHitTestVisible
=
"False"
IsTabStop
=
"False"
Margin
=
"0,0,28,0"
Grid.Row
=
"3"
>
<
telerik:ScrollPositionIndicator.Visibility
>
<
Binding
Mode
=
"TwoWay"
Path
=
"IsScrolling"
RelativeSource
=
"{RelativeSource TemplatedParent}"
>
<
Binding.Converter
>
<
telerik:BooleanToVisibilityConverter
/>
</
Binding.Converter
>
</
Binding
>
</
telerik:ScrollPositionIndicator.Visibility
>
</
telerik:ScrollPositionIndicator
>
<
Border
x:Name
=
"PART_FrozenColumnsPreview"
Background
=
"{DynamicResource {x:Static telerik:GreenResourceKey.AccentLowBrush}}"
HorizontalAlignment
=
"Left"
Opacity
=
"0.1"
Grid.Row
=
"3"
Grid.RowSpan
=
"3"
Visibility
=
"Collapsed"
VerticalAlignment
=
"Stretch"
Width
=
"6"
>
<
Border
BorderBrush
=
"{DynamicResource {x:Static telerik:GreenResourceKey.AccentLowBrush}}"
BorderThickness
=
"1,0,0,0"
HorizontalAlignment
=
"Right"
Width
=
"5"
/>
</
Border
>
<
telerik:GridViewLoadingIndicator
x:Name
=
"PART_GridViewLoadingIndicator"
Grid.ColumnSpan
=
"3"
IsTabStop
=
"False"
IsBusy
=
"{TemplateBinding IsBusy}"
Grid.RowSpan
=
"3"
Visibility
=
"Collapsed"
/>
</
Grid
>
<
ControlTemplate.Triggers
>
<
Trigger
Property
=
"IsBusy"
Value
=
"True"
>
<
Setter
Property
=
"Visibility"
TargetName
=
"PART_GridViewLoadingIndicator"
Value
=
"Visible"
/>
</
Trigger
>
<
Trigger
Property
=
"ShowColumnFooters"
Value
=
"False"
>
<
Setter
Property
=
"Visibility"
TargetName
=
"PART_FooterRow"
Value
=
"Collapsed"
/>
</
Trigger
>
<
Trigger
Property
=
"ShowColumnHeaders"
Value
=
"False"
>
<
Setter
Property
=
"Visibility"
TargetName
=
"PART_HeaderRow"
Value
=
"Collapsed"
/>
</
Trigger
>
<
Trigger
Property
=
"ShowGroupPanel"
Value
=
"False"
>
<
Setter
Property
=
"Visibility"
TargetName
=
"PART_GroupPanel"
Value
=
"Collapsed"
/>
</
Trigger
>
</
ControlTemplate.Triggers
>
</
ControlTemplate
>
</
Setter.Value
>
</
Setter
>
</
Style
>
This will enable Insert, and Remove functionality through the buttons in the stack panel. Of course, you can bind any available command RadGridView exposes.
I hope you find this helpful.
Regards,
Dilyan Traykov
Telerik
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
0
Hello,
Here's the controls namespace from the previous reply:
and the one:
Regards,
Dilyan Traykov
Telerik
Here's the controls namespace from the previous reply:
xmlns:controls="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.GridView"
and the one:
xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
Regards,
Dilyan Traykov
Telerik
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
0
YoungKee
Top achievements
Rank 1
answered on 29 Jun 2016, 10:18 AM
Thanks for your help. i will try it.