Home Forums WPF controls Xceed DataGrid for WPF Columns in a resource

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
  • User (Old forums)
    Post count: 23064
    #25266 |

    I define a datagrid with a fixed set of columns that will be duplicated in a few places in my app. As there are several columns, I’d like to avoid replicating the xaml on different windows. I tried to put the columns into a style but it doesn’t work.

    <Style x:Key=”ServiceGrid” TargetType=”{x:Type xc:DataGridControl}”>
    <Setter Property=”Columns”>
    <xc:Column FieldName=”Tag” Title=”Tag” DisplayMemberBinding=”{Binding First, Mode=TwoWay}”>
    <CheckBox IsChecked=”{xc:CellEditorBinding}” Checked=”CheckBox_Checked”/>
    <xc:Column FieldName=”Loc” Title=”Loc” DisplayMemberBinding=”{Binding Second.LocationCode}”/>
    <!– lots more columns–>

    Error 1 Type ‘ColumnCollection’ is not usable as an object element because it is not public or does not define a public parameterless constructor or a type converter.

    Error 2 The Property Setter ‘Columns’ cannot be set because it does not have an accessible set accessor. Line 71 Position 13.

    anybody have any idea how to go about this?

    Imported from legacy forums. Posted by Colin (had 2426 views)

    Xceed Support
    Post count: 5658

    Effectivelly, this cannot be done as expressed because the Columns property is read-only and the underlying collection type is effectivelly internal (because of the some of the hookups we used).

    My suggestion concerning this would be to consider templating, but on a slightly “broader” approach:

    <ContentControl Content=”{Binding myDataSource}” >
    <xc:DataGridControl ItemsSource=”{Binding}” >
    <!– Define your columns here — >

    This way, the ContentTemplate can be placed in a resource dictionary somewhere, and it can be used with several different data sources…

    Differences between 2 DataGridControls can be addressed by adding implicit styles to the ContentControl’s own resource dictionaries.

    Imported from legacy forums. Posted by Marcus [Xceed] (had 350 views)

    User (Old forums)
    Post count: 23064

    Thanks Marcus, I’ll give that a try.

    Imported from legacy forums. Posted by Colin (had 3632 views)

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.