Can Any Help Me? I Want to load the Column in DataGrid Dymanically As per user preference. The user may be to mention the column order in the Text file. Then According to that, we have shown the column in the data grid.
My data grid has some control on a column like dropdown, text box, Checkbox,
I have added my sample code it is working fine, But in my requirement, I have to load the data grid column as per user preference (Not hardcoded like i am using currently).we can use the text file to configure the column, data grid header should display according to configure column in the text file.
<datagrid
grid.row="1"
="" grid.column="0" grid.columnspan="3" margin="0,4,0,0" padding="0" horizontalalignment="Stretch" verticalalignment="Stretch" autogeneratecolumns="False" canuseraddrows="False" cellstyle="{StaticResource MetroDataGridCell}" columnheaderstyle="{StaticResource DefaultDataGridColumnHeader}" itemssource="{Binding SelectedContact.Recipients, Mode=TwoWay}" rowheaderstyle="{StaticResource MetroDataGridRowHeader}" rowstyle="{StaticResource MetroDataGridRow}" scrollviewer.cancontentscroll="false" scrollviewer.horizontalscrollbarvisibility="Auto" scrollviewer.verticalscrollbarvisibility="Auto">
<datagrid.columns>
<datagridtemplatecolumn header="{x:Static infrastructureLayer:Translations.IsDeleted}">
<datagridtemplatecolumn.celltemplate>
<datatemplate>
<checkbox horizontalalignment="Center" ischecked="{Binding IsDeleted, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">
<datagridtemplatecolumn header="{x:Static infrastructureLayer:Translations.WhatToSend}">
<datagridtemplatecolumn.celltemplate>
<datatemplate>
<combobox
itemssource="{Binding DataContext.WhatToSendTypes, RelativeSource={RelativeSource AncestorType={x:Type DataGrid}, Mode=FindAncestor}}"
="" selectedvalue="{Binding WhatToSendInformationKey, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True}" selectedvaluepath="Identifier">
<datagridtemplatecolumn header="{x:Static infrastructureLayer:Translations.OnlyIfSender}">
<datagridtemplatecolumn.celltemplate>
<datatemplate>
<checkbox horizontalalignment="Center" ischecked="{Binding IsApplicableOnlyIfContactSender, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">
<datagridtemplatecolumn header="{x:Static infrastructureLayer:Translations.HowToSend}">
<datagridtemplatecolumn.celltemplate>
<datatemplate>
<combobox
itemssource="{Binding DataContext.HowToSendTypes, RelativeSource={RelativeSource AncestorType={x:Type DataGrid}, Mode=FindAncestor}}"
="" selectedindex="0" selectedvalue="{Binding HowToSendInformationKey, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True}" selectedvaluepath="Identifier">
<datagridtemplatecolumn header="{x:Static infrastructureLayer:Translations.ClientCode}">
<datagridtemplatecolumn.celltemplate>
<datatemplate>
<textbox isreadonly="True" text="{Binding Path=ClientCode, Mode=TwoWay}">
DataGridTemplateColumn Header="{x:Static infrastructureLayer:Translations.ForAnotherClient}">
<datagridtemplatecolumn.celltemplate>
<datatemplate>
<textbox isreadonly="True" text="{Binding Path=InternalName, Mode=TwoWay}">
<datagridtemplatecolumn header="{x:Static infrastructureLayer:Translations.Language}">
<datagridtemplatecolumn.celltemplate>
<datatemplate>
<combobox
itemssource="{Binding DataContext.ReceipientLanguages, RelativeSource={RelativeSource AncestorType={x:Type DataGrid}, Mode=FindAncestor}}"
="" selectedindex="0" selectedvalue="{Binding LanguageKey, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True}" selectedvaluepath="Identifier">
<datagridtemplatecolumn header="{x:Static infrastructureLayer:Translations.NameDisplay}">
<datagridtemplatecolumn.celltemplate>
<datatemplate>
<checkbox horizontalalignment="Center" ischecked="{Binding IsNameDisplay, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">
<datagridtemplatecolumn header="{x:Static infrastructureLayer:Translations.AddressDisplay}">
<datagridtemplatecolumn.celltemplate>
<datatemplate>
<checkbox horizontalalignment="Center" ischecked="{Binding IsAddressDisplay, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">
What I have tried:
Please help me on this. I am not getting how to achieve this