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

Columns Collection

1 Answer 124 Views
GridView
This is a migrated thread and some comments may be shown as answers.
M
Top achievements
Rank 1
M asked on 23 Mar 2009, 04:45 PM
I am fairly new to WPF and Telerik controls for WPF.  I have been searching google, these forums, and more to try and figure out what I believe should be easy enough to do.  I would like to set up a RadGridView to have a list of columns in a "style" or resource so I can use it on multiple pages.  Here is an example of what I tried to do:
<Style x:Key="myGrid" TargetType="{x:Type telerik:RadGridView}"
 <Setter Property="Template"
  <Setter.Value> 
   <ControlTemplate TargetType="telerik:RadGridView"
    <AdornerDecorator> 
     <Border Name="PART_MasterGridContainer" Grid.Row="1"  BorderThickness="1" Background="White" BorderBrush="#FF9EB6CE"
      <telerik:GridViewItemsControl x:Name="PART_RootItemsControl" 
       IsHierarchyRoot="{TemplateBinding IsHierarchyRoot}" 
       ParentRow="{TemplateBinding ParentRow}" 
       ScrollMode ="{TemplateBinding ScrollMode}" 
       ShowColumnHeaders="{TemplateBinding ShowColumnHeaders}" 
       ShowGroupPanel="{TemplateBinding ShowGroupPanel}" /> 
     </Border> 
    </AdornerDecorator> 
   </ControlTemplate> 
  </Setter.Value> 
 </Setter> 
 <Setter Property="ColumnsWidthMode" Value="Fill" /> 
 <Setter Property="Width" Value="Auto" /> 
 <Setter Property="Height" Value="Auto" /> 
 <Setter Property="VerticalGridlinesVisibility" Value="Hidden" /> 
 <Setter Property="telerik:RadGridView.Columns"
  <Setter.Value> 
   <telerik:GridViewColumnCollection> 
    <telerik:GridViewDataColumn DataType="{x:Null}" HeaderText="Image" UniqueName="ImageName" IsGroupable="False" IsSortable="False" Width="50" CellStyle="{StaticResource ImageCell}" />
    <telerik:GridViewDataColumn DataType="{x:Null}" HeaderText="ColA" UniqueName="ColA" IsGroupable="False" IsSortable="False" Width="50" /> 
    <telerik:GridViewDataColumn DataType="{x:Null}" HeaderText="ColB" UniqueName="ColB" IsGroupable="False" IsSortable="False" Width="50" /> 
    <telerik:GridViewDataColumn DataType="{x:Null}" HeaderText="ColC" UniqueName="ColC" IsGroupable="False" IsSortable="False" Width="50" /> 
    <telerik:GridViewDataColumn DataType="{x:Null}" HeaderText="ColD" UniqueName="ColD" IsGroupable="False" IsSortable="False" Width="50" /> 
   </telerik:GridViewColumnCollection> 
  </Setter.Value> 
 </Setter> 
</Style>
but the "Columns" property is read only.  I tried searching for ways to add items to collections within XAML, but I could not find any ways to do this.  In my mind, this seems like it should be fairly easy to acomplish, but it never truly is :P

1 Answer, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 24 Mar 2009, 04:04 PM
Hi M,

I don't believe that this is possible. Maybe the best approach will be to create a user control with desired grid settings and reuse this user control in your application.

Kind regards,
Vlad
the Telerik team

Check out Telerik Trainer , the state of the art learning tool for Telerik products.
Tags
GridView
Asked by
M
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Share this question
or