Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
340
How to change Header Text in XAMGrid in Code behind
posted

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

Parents
No Data
Reply
  • 34510
    Offline posted

    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);

Children