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

Bound header wrapping issue

2 Answers 114 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Russ
Top achievements
Rank 1
Russ asked on 12 Jul 2011, 06:04 PM

I'm having an issue with column header wrapping due to my headers being bound to the DisplayName attribute of my properties.

I have a Property in my view model, using the DisplayName attribute:

[DisplayName("Component Item Identifier")]
public String ComponentItem
{
    get { return componentItem; }
    set
    { ... }
}

I can make that display in the header using:
<telerikGrid:GridViewDataColumn  UniqueName="ComponentItem" 
             DataMemberBinding="{Binding Path=ComponentItem}" 
             Header="{Binding Path=ComponentItem.DisplayName}" >
</telerikGrid:GridViewDataColumn>

However, I need to make the header column wrap the text.  The method I've found in these forums is via using a TextBlock as the header UI element, and I can make that work without the bindings:
<telerikGrid:GridViewDataColumn  UniqueName="ComponentItem"
DataMemberBinding="{Binding Path=ComponentItem}">
    <telerikGrid:GridViewDataColumn.Header>
        <Grid>
            <TextBlock Text="MY LONG TEXT FOR TESTING WRAPPING" TextWrapping="Wrap"/>
        </Grid>
     </telerikGrid:GridViewDataColumn.Header>                            
</telerikGrid:GridViewDataColumn>

But, the problem comes when I try to bind that TextBlock to my DisplayName, as follows, the header ends up blank:
<telerikGrid:GridViewDataColumn  UniqueName="ComponentItem"
DataMemberBinding="{Binding Path=ComponentItem}"
    <telerikGrid:GridViewDataColumn.Header
        <Grid
            <TextBlock Text="{Binding Path=ComponentItem.DisplayName}" TextWrapping="Wrap"/> 
        </Grid
     </telerikGrid:GridViewDataColumn.Header>                             
</telerikGrid:GridViewDataColumn>

Am I binding incorrectly in this code?  Or is this just not supported in this structure?

Sincerely,
Russell.






2 Answers, 1 is accepted

Sort by
0
Accepted
Milan
Telerik team
answered on 13 Jul 2011, 07:26 AM
Hello Russ,

This is expected behavior since our columns are not visual elements and are not part of the visual tree - their data context is not the one that you would expect. The solution is to explicitly instruct the binging that its source is your ViewModel.

  The project that I have attached demonstrates two possible implementations - the first one uses a ViewModel that can be instantiated in XAML and the second one demonstrates how you can deal with a ViewModel that can only be instantiated in code.

Hope this helps.

Regards,
Milan
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

0
Russ
Top achievements
Rank 1
answered on 13 Jul 2011, 01:14 PM
Thanks, I can see how it is working in your sample project.  But it is not working in my version.  We haven't upgraded beyond 2010 Q3 yet, so that is most likely the problem in my case.  I'll take a look again when we upgrade in the near future.
Tags
GridView
Asked by
Russ
Top achievements
Rank 1
Answers by
Milan
Telerik team
Russ
Top achievements
Rank 1
Share this question
or