Possible to set columns in RadDataGrid from XAML style or contentpresenter?

4 posts, 0 answers
  1. Jasper
    Jasper avatar
    8 posts
    Member since:
    Dec 2015

    Posted 22 May Link to this post

    Would it be possible to set the column definitions for a RadDataGrid from a XAML style or ContentPresenter?

    I have created a datagrid with a datapager, number of results dropdown, and group, and filter translation to an rpc-database backend.
    I would now like to put all these components in a custom usercontrol, which has my IRpcViewModel of various database models as datacontext.

    This way I'm hoping to use the same xaml/codebase for the datagrid presentation of different models.

     

    Basically I'd like to have an implementation for the following in pseudo code:

     

    <MyRpcDataGrid ItemsSource="{Binding ItemList}">
      <grid:DataGridTextColumn PropertyName="PurOrdNr" Header="Order" CanUserEdit="False" />
      <grid:DataGridTextColumn PropertyName="Description" Header="Description" />
      <grid:DataGridNumericalColumn PropertyName="PartCode" Header="Artikel" />
    </MyRpcDataGrid>

    With something like this as UserControl:

    <UserControl x:Class="MyApp.MyRpcDataGrid" xmlns:grid="using:Telerik.UI.Xaml.Controls.Grid">
        <UserControl.Content>
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="*" />
                        <RowDefinition Height="Auto" />
                    </Grid.RowDefinitions>
     
                    <grid:RadDataGrid Grid.Row="0" x:Name="dataGrid">
                        <grid:RadDataGrid.Columns>
                            <ContentPresenter>
                        </grid:RadDataGrid.Columns>
                    </grid:RadDataGrid>
                     
                    <RadBusyIndicator Grid.Row="0" IsActive="{Binding IsLoading}" />
                     
                    <PaginationToolbar Grid.Row="1">
     
                </Grid>
        </UserControl.Content>
    </UserControl>

     

    Is there any example available with columns set based on parameters/styles from outside the control itself?

     

  2. Tsvyatko
    Admin
    Tsvyatko avatar
    833 posts

    Posted 24 May Link to this post

    Hello Jasper,

    Thank you for contacting us! In your scenario I can recommend two possible approaches:

    1. Utilize the autogenerate columns capabilities of data grid (AutoGenerateColumns = true) and use GenerateColumn Command to setup each column as desired. A convenient way to do it is to expose a command property of your user control.

    2. Declarative way to setup it in xaml. Turn off autogenerate columns capability of DataGrid and expose Column property to your user control. The setup will look like that:
    public DataGridColumnCollection Columns
    {
        get
        {
            return this.grid.Columns;
        }
    }

    And the usage will be:
    <local:MyRpcDataGrid>
               <local:MyRpcDataGrid.Columns>
                   <telerikGrid:DataGridTextColumn PropertyName="ID"/>
                   <telerikGrid:DataGridTextColumn PropertyName="Name"/>
               </local:MyRpcDataGrid.Columns>
           </local:MyRpcDataGrid>


    I have prepared sample demonstrating the approach. Let us know if this helps.

    Regards,
    Tsvyatko
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. DevCraft banner
  4. Jasper
    Jasper avatar
    8 posts
    Member since:
    Dec 2015

    Posted 24 May in reply to Tsvyatko Link to this post

    That's excellent Tsvyatko. 

    We're currently evaluating the controls.

    Support like this and the fact that Telerik designed the controls adhering to MVVM principles is a big plus for us.

    So far Telerik's datagrid seems to be the best choice for our application.

    The only thing I seem to be missing so far is built in support for DataAnnotations.

  5. Tsvyatko
    Admin
    Tsvyatko avatar
    833 posts

    Posted 26 May Link to this post

    Hello Jasper,

    I am glad that our controls are good fit for your architecture and business case. We do appreciate any feedback that will help us to improve them further. That being said, would it be possible to share more information regarding the scenario requiring DataAnnotations support - how is the data fed, what kind of external source do you use, what annotation attributes do you use.

    This information will help us better understand the scenarios and our future implementation of features in more convenient to use way.

    Furthermore, you can log this feature in our feedback portal - http://feedback.telerik.com/Project/167/. Our roadmap is heavily influenced by customer feedback. If it become popular feature we will include it in roadmap with higher priority.

    Regards,
    Tsvyatko
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top
DevCraft banner