This is a migrated thread and some comments may be shown as answers.

Binding GridViewColumnGroup in TreListView

3 Answers 28 Views
TreeListView
This is a migrated thread and some comments may be shown as answers.
Pablo
Top achievements
Rank 1
Pablo asked on 18 Nov 2016, 04:05 PM

Dear,

Binding 'Header' property to DataContext in a GridVewColumnGroup doesn't work. Public property is not requested to DataContext.

    <telerik:GridViewColumnGroup Name="RangeColumn" Header="{Binding FirstDependencyName, FallbackValue=Nothing}" />

By other hand, a binding to StaticResource works property.

    <telerik:GridViewColumnGroup Name="RangeColumn" Header="{Binding Source={StaticResource appResx}, Path=btn_Create}" />

In next example, public property is requested to DataContext (value is received tested with a converter), but surprisingly it is not displayed.

    <telerik:GridViewColumnGroup Name="RangeColumn">
        <telerik:GridViewColumnGroup.Header>
            <TextBlock Text="{Binding FirstDependencyName, FallbackValue=Nothing}"/>
        </telerik:GridViewColumnGroup.Header>
    </telerik:GridViewColumnGroup>

Do you have any suggestion?
Thank you

3 Answers, 1 is accepted

Sort by
0
Dilyan Traykov
Telerik team
answered on 21 Nov 2016, 01:01 PM
Hello Pablo,

In order to successfully bind the Header property to a property of your view model, you will need to specify the Source for this binding. I'm attaching a sample project with the implementation.

Please let me know if this works for you.

Regards,
Dilyan Traykov
Telerik by Progress
Telerik UI for WPF is ready for Visual Studio 2017 RC! Learn more.
0
Peter
Top achievements
Rank 1
answered on 20 Dec 2018, 02:43 AM

Actually there is a problem with this solution. The header value is hard coded in the view model as:

public string Header { get; set; } = "Header from VM";

I tried setting Mode=TwoWay, but it didn't work. Header is updated at run time and the binding does not get updated.

Header="{Binding Header, Source={StaticResource MyViewModel}, FallbackValue=Nothing}"

I did a work around by handling it in code behind.

0
Dilyan Traykov
Telerik team
answered on 21 Dec 2018, 09:50 AM
Hello Peter,

In order for the GridViewColumnGroup's header to be successfully updated, it needs to invoke a property changed notification. I've defined the property with an automatic getter and setter in the project for simplicity but if you require runtime changes to the property, you can define it like so:

 
private string header;
 
public string Header
{
    get { return header; }
    set
    {
        header = value;
        OnPropertyChanged("Header");
    }
}

I hope you find this information helpful. Please let me know if such an approach works for you.

Regards,
Dilyan Traykov
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
TreeListView
Asked by
Pablo
Top achievements
Rank 1
Answers by
Dilyan Traykov
Telerik team
Peter
Top achievements
Rank 1
Share this question
or