Unplanned
Last Updated: 25 Oct 2020 11:36 by Sławomir
ADMIN
Martin
Created on: 23 Nov 2016 07:13
Category: GridView
Type: Bug Report
5
GridView : If in the content of RadGridView.ControlPanelItem has a binding with a RelativeSource or ElementName and the grid is placed in the collapsed UserControl, a binding error is thrown in the ou
If in the content of RadGridView.ControlPanelItem has a binding with a RelativeSource or ElementName and the grid is placed in the collapsed UserControl, a binding error is thrown in the output window.
9 comments
Sławomir
Posted on: 25 Oct 2020 11:36

Dear All,

I had the very same issue both with ControlPaneltem as well as the ColumnFooter.

By default they both use a different DataContext than the UserControl. So, we may try to use Binding via RelativeSource or ElementName to the master DataContext. This approach works for me if a FrameworkElement is visible. If it is collapsed, then it does not work. 

A workaround is to use a StaticResource DataContext. But what if we use DI or autowire the DataContext (e.g. using Prism) and do not want to define the ViewModel is xaml as in Dinko’s solution?

A simple workaround (that worked for me) is to use a DataContext proxy.

1. In UserControl.Resources you declare a dummy FrameworkElement (proxy)

2. In the UserControl you place a collapsed ContentControl with the proxy used as a StaticResource content (this way the proxy will get the DataContext).

3. Finally, we set the DataContext of a given element (e.g. ControlPanelItem or Footer) to the StaticResource and then bind to its DataContext.

See below:

<UserControl.Resources>
    <FrameworkElement x:Key="DataContextProxy"></FrameworkElement>
</UserControl.Resources>
<UserControl>
    <Grid>
        <ContentControl Content={StaticResource DataContextProxy} Visibility="Collapsed"/>
        <telerik:RadGridView>
            <telerik:RadGridView.Columns>
            ...
                <telerik:GridViewDataColumn ...>
                    <telerik:GridViewDataColumn.Footer>
                     <TextBlock DataContext="{StaticResource DataContextProxy}" Text="{Binding DataContext.SomeProperty}" />
                    </telerik:GridViewDataColumn.Footer>
                </telerik:GridViewDataColumn>
            </telerik:RadGridView.Columns>
            ...
        </telerik:RadGridView>
    </Grid>
</UserControl>

 

ADMIN
Dinko | Tech Support Engineer
Posted on: 05 May 2020 08:02

Hi David,

To better assist you, is it possible to create a sample project that mimics your set-up. This way, I can have a better look and think for a suitable solution.

Regards,
Dinko
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
David
Posted on: 28 Apr 2020 21:24

We cannot use the solution proposed, because we depend on dependency injection to create 

our models

David
Posted on: 28 Apr 2020 21:20
Can someone please look at this issue and fix it. It would be really appreciated.
ADMIN
Dinko | Tech Support Engineer
Posted on: 14 Apr 2020 10:20

Hi Joe,

I'm afraid that this behavior have been planned for fixing. You can subscribe to it so that you can get notified of its status changed.

As a workaround, you can specify your ViewModel as a StaticResource. Check the following code snippet. This way you are directly binding to the command and not looking for a parent data context. 

<Window.Resources>
    <local:MyViewModel x:Key="MyViewModel"/>
</Window.Resources>

<telerik:ControlPanelItem ButtonTooltip="Column chooser">
    <telerik:ControlPanelItem.ButtonContent>
        <Button Command="{Binding Path=ButtonCommand, Source={StaticResource MyViewModel}, UpdateSourceTrigger=PropertyChanged }" Content="Click me"/>
    </telerik:ControlPanelItem.ButtonContent>
</telerik:ControlPanelItem>

Regards,
Dinko
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
Joe
Posted on: 07 Apr 2020 17:15
Am I correct in assuming this has not yet been fixed?  I spent a few hours today debugging a completely mystifying failure to bind that at least appears to be caused by this.  If this has not been fixed, I have my answer.  If this *has* been fixed then I need to keep trying to figure it out.
ADMIN
Martin
Posted on: 07 Mar 2018 09:47
We can not commit to a certain time frame for fixing this bug. You can subscribe to the feedback item in order to receive notifications. Once we start to work on the bug the feedback item's status will be changed to "In Development".
erhan
Posted on: 18 Jan 2018 12:57
Hi,

Have you fixed the problem
erhan
Posted on: 23 Nov 2016 07:32
I have the same problem