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

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

    Hi,
    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”>
    <Setter.Value>
    <xc:ColumnCollection>
    <xc:Column FieldName=”Tag” Title=”Tag” DisplayMemberBinding=”{Binding First, Mode=TwoWay}”>
    <xc:Column.CellEditor>
    <xc:CellEditor>
    <xc:CellEditor.EditTemplate>
    <DataTemplate>
    <CheckBox IsChecked=”{xc:CellEditorBinding}” Checked=”CheckBox_Checked”/>
    </DataTemplate>
    </xc:CellEditor.EditTemplate>
    </xc:CellEditor>
    </xc:Column.CellEditor>
    </xc:Column>
    <xc:Column FieldName=”Loc” Title=”Loc” DisplayMemberBinding=”{Binding Second.LocationCode}”/>
    <!– lots more columns–>
    </xc:ColumnCollection>
    </Setter.Value>
    </Setter>
    </Style>

    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
    Member
    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}” >
    <ContentControl.ContentTemplate>
    <DataTemplate>
    <xc:DataGridControl ItemsSource=”{Binding}” >
    <!– Define your columns here — >
    <xc:DataGridControl>
    </DataTemplate>
    </Contentcontrol.ContentTemplate>
    </ContentControl>

    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)
    Member
    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.