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

Wrapping text in GridViewColumn.Header

4 Answers 143 Views
GridView
This is a migrated thread and some comments may be shown as answers.
D. Omar
Top achievements
Rank 1
D. Omar asked on 11 Sep 2009, 07:41 PM
In this thread (http://www.telerik.com/community/forums/silverlight/gridview/wrap-header-text.aspx) it is mentioned that a property is going to be added to text wrapping. Is that there yet or do I sill have to do it as the sample solution in that thread?

Thanks in advance,

-OmarV

4 Answers, 1 is accepted

Sort by
0
Accepted
Kalin Milanov
Telerik team
answered on 14 Sep 2009, 06:42 AM
Hi D. Omar,

Unfortunately the property is not yet available and your best bet is still using the approach described in that thread. I am also attaching you a sample which does the same - it just uses the latest binaries (Q2 SP1).

Greetings,
Kalin Milanov
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
D. Omar
Top achievements
Rank 1
answered on 30 Sep 2009, 02:04 AM
Ok, I need to have full crontrol on what goes on which line rather than leaving it to the AlignmentContentPresenter control to do the wrapping. I figured out I could just set it in XAML like this:

<telerikGridView:GridViewDataColumn UniqueName="MyColumn">  
   <telerikGridView:GridViewDataColumn.Header> 
      <StackPanel> 
         <TextBlock Text="Line1" /> 
         <TextBlock Text="Line2" /> 
      </StackPanel> 
   </telerikGridView:GridViewDataColumn.Header> 
</telerikGridView:GridViewDataColumn> 

But I need to do it programmatically as the data for the header comes from a data source. I tried the following code and it did not work, am I doing something wrong?

var header = new StackPanel();  
header.Children.Add(new TextBlock { Text = "Line1"TextAlignmentTextAlignment=TextAlignment.Center } );  
header.Children.Add(new TextBlock { Text = "Line2"TextAlignmentTextAlignment=TextAlignment.Center } );  
ret.Header = header

Here is the exception information:

{System.Windows.Markup.XamlParseException:  [Line: 0 Position: 0]  
   --- Inner Exception ---  
Element is already the child of another element.  
 ---> System.InvalidOperationException: Element is already the child of another element.  
   at MS.Internal.XcpImports.CheckHResult(UInt32 hr)  
   at MS.Internal.XcpImports.SetValue(INativeCoreTypeWrapper obj, DependencyProperty property, DependencyObject doh)  
   at MS.Internal.XcpImports.SetValue(INativeCoreTypeWrapper doh, DependencyProperty property, Object obj)  
   at System.Windows.DependencyObject.SetObjectValueToCore(DependencyProperty dp, Object value)  
   at System.Windows.DependencyObject.SetValueInternal(DependencyProperty dp, Object value, Boolean allowReadOnlySet, Boolean isSetByStyle, Boolean isSetByBuiltInStyle, PropertyInvalidationReason reason)  
   at System.Windows.DependencyObject.SetValueInternal(DependencyProperty dp, Object value)  
   at System.Windows.DependencyObject.SetValue(DependencyProperty dp, Object value)  
   at System.Windows.Controls.ContentControl.set_Content(Object value)  
   at Telerik.Windows.Controls.GridView.GridViewHeaderCell.SetHeaderText()  
   at Telerik.Windows.Controls.GridView.GridViewHeaderCell.OnApplyTemplate()  
   at System.Windows.FrameworkElement.OnApplyTemplate(IntPtr nativeTarget)  
   --- End of inner exception stack trace ---  
   at MS.Internal.XcpImports.MethodEx(IntPtr ptr, String name, CValue[] cvData)  
   at MS.Internal.XcpImports.MethodEx(DependencyObject obj, String name)  
   at MS.Internal.XcpImports.FrameworkElement_ApplyTemplate(FrameworkElement frameworkElement)  
   at System.Windows.FrameworkElement.ApplyTemplateInternal()  
   at System.Windows.Controls.Control.ApplyTemplate()  
   at Telerik.Windows.Controls.GridView.GridViewDataControl.<PopulateHeaderAndFooterRows>b__45(GridViewCellBase c)  
   at System.Collections.Generic.List`1.ForEach(Action`1 action)  
   at Telerik.Windows.Controls.GridView.GridViewDataControl.PopulateHeaderAndFooterRows()  
   at Telerik.Windows.Controls.GridView.GridViewDataControl.OnColumnsCollectionChanged(NotifyCollectionChangedEventArgs e)  
   at Telerik.Windows.Controls.GridViewColumnCollection.OnCollectionChanged(NotifyCollectionChangedEventArgs e)  
   at System.Collections.ObjectModel.ObservableCollection`1.InsertItem(Int32 index, T item)  
   at Telerik.Windows.Data.RadObservableCollection`1.InsertItem(Int32 index, T item)  
   at System.Collections.ObjectModel.Collection`1.Add(T item)  
   at Perquest.Payroll.Worksheet.Silverlight.TelerikWorksheetGrid._gridManager_WorksheetColumnsCreated(Object sender, WorksheetColumnsCreatedEventArgs e)} 




0
Vlad
Telerik team
answered on 30 Sep 2009, 11:56 AM
Hi,

I've tried this using both our latest internal build and our official service pack and everything worked fine. You can check the attached project.

Best wishes,
Vlad
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Mark
Top achievements
Rank 1
answered on 13 Feb 2012, 07:23 AM
Vlad
Is there an updated solution to this issue. Is the issue going to be addressed in the next release (I am willing to wait for that release!)
Tags
GridView
Asked by
D. Omar
Top achievements
Rank 1
Answers by
Kalin Milanov
Telerik team
D. Omar
Top achievements
Rank 1
Vlad
Telerik team
Mark
Top achievements
Rank 1
Share this question
or