Hi,
We are using XAMGrid and we are going to bind header Text dynamically. Our requirement is that As we select the row as per row selection the header text will be changed. For that we make bind Header text in ViewModel. But Header Text are not showing in UI View.
Please help us for updating Header Text in XAMGrid.
Thanks
Hi piyu,
Bindings won't work on the HeaderText property because the column object (i.e. TextColumn, ComboBoxColumn, etc) does not exist within the visual tree. You will also notice that these columns do not have a DataContext property. So binding to anything other than a StaticResource will not work.
There are a two ways to can get around this. The first is to declare your view model as a StaticResource in the XAML page and then change all your bindings to be "{Binding Source={StaticResource myVM} Path=myproperty}". The second option is to bind the column HeaderText property to your view model property in code-behind:
Binding b = new Binding("ViewModelHeaderProperty");b.Source = vm;b.Mode = BindingMode.TwoWay;BindingOperations.SetBinding(column, ColumnBase.HeaderTextProperty, b);
Thanks for your Reply. I have applied First approach but Header text Property are not going to visible in XAMGrid.
In XAML defined Viewmodel in Key:
<local:GlobalHistoryRecordInfoVM x:Key="globalHistoryKey"/> <ig:XamGrid x:Name="dataGlobalHistoryView" ItemsSource="{Binding Path=globalHistoryRecordInfo}" AutoGenerateColumns="False" " SelectedRowsCollectionChanged="dataGlobalHistoryView_SelectedRowsCollectionChanged"> <ig:XamGrid.EditingSettings> <ig:EditingSettings AllowEditing="None" /> </ig:XamGrid.EditingSettings> <ig:XamGrid.SelectionSettings> <ig:SelectionSettings CellClickAction="SelectRow" RowSelection="Single" /> </ig:XamGrid.SelectionSettings> <ig:XamGrid.RowSelectorSettings> <ig:RowSelectorSettings Visibility="Hidden"/> </ig:XamGrid.RowSelectorSettings> <ig:XamGrid.Columns>
<ig:TextColumn Key="Param2" Width="Auto" > <ig:TextColumn.HeaderTemplate> <DataTemplate> <TextBlock Text="{Binding Source={StaticResource globalHistoryKey}, Path= ModelHistory .ParamHeader2}" Name="txtBlockHeader2" FontSize="12" /> </DataTemplate> </ig:TextColumn.HeaderTemplate> </ig:TextColumn>
</ig:XamGrid.Columns> </ig:XamGrid>
Now in ViewModel I have assigned ColumnHeader Text..
public GlobalHistoryRecordInfoVM() { ModelHistory = new GlobalHistoryModel(); ModelHistory.ParamHeader2 = "Param2"; }
Above I have assigned Param2 as Header Text. But Param2 is not going to visible in Grid Header..
Please let us aware..