Report a Silverlight Bughttp://forums.silverlight.net//28.aspx/1?Report+a+Silverlight+BugFound a bug in Silverlight? Use this forum to describe the bug and the code or steps to reproduce it.Mon, 01 Jan 0001 00:00:00 -05002897847http://forums.silverlight.net//p/30592/97847.aspx/1?Custom+DataGrid+Header+BUG+in+RC0+Custom DataGrid.Header - BUG in RC0. This code works fine:&nbsp; <pre class="prettyprint">DataGridTextColumn dgtc = <SPAN class=kwd>new</SPAN> DataGridTextColumn(); dgtc.Header = <SPAN class=st>"AAA"</SPAN>; // OK!!! theDataGrid.Columns.Add(dgtc); </pre> <P mce_keep="true">And this&nbsp;code&nbsp;can be compiled, but after running&nbsp;generates an ERROR (VS2008 Standard SP1, IE 7.0):</P><pre class="prettyprint">DataGridTextColumn dgtc = <SPAN class=kwd>new</SPAN> DataGridTextColumn(); TextBlock tb = <SPAN class=kwd>new</SPAN> TextBlock(); tb.Text = <SPAN class=st>"AAA"</SPAN>; dgtc.Header = tb; <SPAN class=cmt>// A BUG !!!</SPAN> theDataGrid.Columns.Add(dgtc);</pre> <p>Any other custom header doesn't work, too. This bug destroyed all my project based on&nbsp;big number of DataGrids with custom DataGridTemplateColumns with custom Headers. This worked very nice in Beta2 !</p> <p>B.</p> <p>&nbsp;</p> <p>&nbsp;</p> 2008-09-26T15:54:45-04:0097872http://forums.silverlight.net//p/30592/97872.aspx/1?Re+Custom+DataGrid+Header+BUG+in+RC0+Re: Custom DataGrid.Header - BUG in RC0. <p>&nbsp;I found the same thing. How do we set the Header to a control now?</p> <p>&nbsp;</p> 2008-09-26T16:31:04-04:0098478http://forums.silverlight.net//p/30592/98478.aspx/1?Re+Custom+DataGrid+Header+BUG+in+RC0+Re: Custom DataGrid.Header - BUG in RC0. <p>I found the same thing too, in additon binding the Header to a static resource is also not possible:</p> <p><font color="#0000ff" size="2"><font color="#0000ff" size="2">&lt;</font></font><font color="#a31515" size="2"><font color="#a31515" size="2">data</font></font><font color="#0000ff" size="2"><font color="#0000ff" size="2">:</font></font><font color="#a31515" size="2"><font color="#a31515" size="2">DataGridTextColumn</font></font><font size="2"> <br> </font><font color="#ff0000" size="2"><font color="#ff0000" size="2">Header</font></font><font color="#0000ff" size="2"><font color="#0000ff" size="2">=&quot;{</font></font><font color="#a31515" size="2"><font color="#a31515" size="2">Binding</font></font><font color="#ff0000" size="2"><font color="#ff0000" size="2"> Field_Name</font></font><font color="#0000ff" size="2"><font color="#0000ff" size="2">,</font></font><font color="#ff0000" size="2"><font color="#ff0000" size="2"> Source</font></font><font color="#0000ff" size="2"><font color="#0000ff" size="2">={</font></font><font color="#a31515" size="2"><font color="#a31515" size="2">StaticResource</font></font><font color="#ff0000" size="2"><font color="#ff0000" size="2"> losTransport</font></font><font color="#0000ff" size="2"><font color="#0000ff" size="2">}}&quot;<br> </font></font><font color="#ff0000" size="2"><font color="#ff0000" size="2">Binding</font></font><font color="#0000ff" size="2"><font color="#0000ff" size="2">=&quot;{</font></font><font color="#a31515" size="2"><font color="#a31515" size="2">Binding</font></font><font color="#ff0000" size="2"><font color="#ff0000" size="2"> Name</font></font><font color="#0000ff" size="2"><font color="#0000ff" size="2">}&quot;</font></font><font size="2"> <br> </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">/&gt;</font></font></p> <p><font color="#0000ff" size="2"><font color="#0000ff" size="2">It raises AG_E_PARSER_BAD_PROPERTY_VALUE [Line: 82 Position: 13]</font></font></p> <p><font color="#0000ff" size="2"><font color="#0000ff" size="2"></font></font>&nbsp;</p> <p><font color="#0000ff" size="2"><font color="#0000ff" size="2">&nbsp;</p> </font></font> 2008-09-27T19:25:07-04:0098651http://forums.silverlight.net//p/30592/98651.aspx/1?Re+Custom+DataGrid+Header+BUG+in+RC0+Re: Custom DataGrid.Header - BUG in RC0. <p>I have found the same issue and its a huge problem I have lots of checkbox columns and I use the header template to have a check all check box.&nbsp; Used to work perfectly in Beta 2 but now if I use the XAML below I either get an exception in the renderer or my Visual Studio totally freezes and CPU maxes out like its got stuck in a loop I have had to remove all header template in my grids just to get it working.</p> <font color="#008000" size="2"><font color="#008000" size="2"> <p>&lt;data:DataGridTemplateColumn&gt;</p> <p>&lt;data:DataGridTemplateColumn.Header&gt;</p> <p>&lt;CheckBox HorizontalAlignment=&quot;Center&quot; x:Name=&quot;chkSelectAll&quot; Click=&quot;chkSelectAll_Click&quot; /&gt;</p> <p>&lt;/data:DataGridTemplateColumn.Header&gt;</p> <p></font>&nbsp;</p> &nbsp;</font> 2008-09-28T11:07:34-04:0099042http://forums.silverlight.net//p/30592/99042.aspx/1?Re+Custom+DataGrid+Header+BUG+in+RC0+Re: Custom DataGrid.Header - BUG in RC0. <p>&nbsp;</p> <p>Hello, DataGrid is an SDK Control (not in the runtime, and is not written by the Silverlight team. It's written by the UIFX team, AKA the team responsible for Windows Forms and ASP.NET). Please understand the time was limited, so not every team made the break changes list. But I think they will include the break changes in RTW documentation. Anyway, here're the break changes for DataGrid I got internally (removed any internal links and confidential information):</p> <ul> <li>DisplayMemberBinding renamed to Binding. </li><li>The ControlTemplate contract changed to use VisualState. </li><li>IEditableObject moved to System.ComponentModel. </li><li>SelectionChanged event now uses SelectionChangedEventHandler instead of EventHandler. </li><li>DataGridHeaders enum renamed to DataGridHeadersVisibility. </li><li>The PropertyInfo of DataGridAutoGeneratingColumnEventArgs was changed to PropertyName and PropertyType.<br> <br> Beta 2<br> string name = e.Property.Name;<br> Type type = e.Property.Type;<br> <br> RC<br> string name = e.PropertyName;<br> Type type = e.PropertyType;</li></ul> <p>&nbsp;</p> <ul> <li>GenerateElement and GenerateEditingElement now provide the containing cell<br> <br> Beta 2<br> protected override FrameworkElement GenerateEditingElement(object dataItem)<br> {<br> }<br> protected override FrameworkElement GenerateElement(object dataItem)<br> {<br> }<br> <br> RC<br> protected override FrameworkElement GenerateEditingElement(DataGridCell cell, object dataItem)<br> {<br> }<br> protected override FrameworkElement GenerateElement(DataGridCell cell, object dataItem)<br> {<br> }</li></ul> <p>&nbsp;</p> <ul> <li>The following modifications were made to the DataGridColumnReorderingEventArgs:<br> Beta 2:<br> public object DragIndicatorContent { get; set}<br> public FrameworkElement DropLocationIndicator { get; set}<br> RC:<br> public Control DragIndicator { get; set}<br> public Control DropLocationIndicator { get; set}</li></ul> <p>&nbsp;</p> <ul> <li>CancelingEdit, CommittingEdit, and DataError events removed. </li><li><strong>DataGridColumn.Header no longer supports visuals.</strong>Explaination: Visuals cannot be duplicated so they cannot be used for the Header property due to column reordering. Use HeaderStyle instead:<br> &lt;data:DataGridTextColumn.HeaderStyle&gt;<br> &lt;Style TargetType=&quot;dataprimitives:DataGridColumnHeader&quot;&gt;<br> &lt;Setter Property=&quot;Template&quot;&gt;<br> &lt;Setter.Value&gt;<br> &lt;ControlTemplate&gt;<br> &lt;Button Content=&quot;{TemplateBinding Content}&quot; /&gt;<br> &lt;/ControlTemplate&gt;<br> &lt;/Setter.Value&gt;<br> &lt;/Setter&gt;<br> &lt;/Style&gt;<br> &lt;/data:DataGridTextColumn.HeaderStyle&gt; </li></ul> <ul> <li>Root element of DataGridRow changed from Grid to DataGridFrozenGrid. </li><li>Gridline renamed to GridLine. </li><li>These types moved from the System.Windows.Controls namespace to the System.Windows.Controls.Primitives namespace:<br> DataGridCellsPresenter<br> DataGridColumnHeadersPresenter<br> DataGridDetailsPresenter<br> DataGridRowsPresenter<br> DataGridColumnHeader<br> DataGridRowHeader </li><li>DataGridCheckBoxColumn.Content was removed.</li></ul> <p>Note now you have to use HeaderStyle if you want anything other than plain text.</p> 2008-09-29T09:49:47-04:0099166http://forums.silverlight.net//p/30592/99166.aspx/1?Re+Custom+DataGrid+Header+BUG+in+RC0+Re: Custom DataGrid.Header - BUG in RC0. <p>Thanks for extending the breaking changes list. </p> <p>As for the ColumnHeader style ...&nbsp;I've tried to use the example into App.xaml:</p> <pre class="prettyprint"><APPLICATION class=st xmlns="<span"><pre class="prettyprint">&lt;<SPAN class=tag>Application</SPAN><SPAN class=attr> xmlns=</SPAN><SPAN class=attrv>"http://schemas.microsoft.com/winfx/2006/xaml/presentation"</SPAN> <SPAN class=attr> xmlns:x=</SPAN><SPAN class=attrv>"http://schemas.microsoft.com/winfx/2006/xaml"</SPAN> <SPAN class=attr> xmlns:dataprimitives=</SPAN><SPAN class=attrv>"clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data"</SPAN> <SPAN class=attr> x:Class=</SPAN><SPAN class=attrv>"GridHeaderTest.App"</SPAN> &gt; &lt;<SPAN class=tag>Application.Resources</SPAN>&gt; <SPAN class=cmt>&lt;!--Style for ColumnHeader --&gt;</SPAN> &lt;<SPAN class=tag>Style</SPAN><SPAN class=attr> x:Key=</SPAN><SPAN class=attrv>"ColumnHeaderStyle"</SPAN><SPAN class=attr> TargetType=</SPAN><SPAN class=attrv>"dataprimitives:DataGridColumnHeader"</SPAN>&gt; &lt;<SPAN class=tag>Setter</SPAN><SPAN class=attr> Property=</SPAN><SPAN class=attrv>"Template"</SPAN>&gt; &lt;<SPAN class=tag>Setter.Value</SPAN>&gt; &lt;<SPAN class=tag>ControlTemplate</SPAN>&gt; &lt;<SPAN class=tag>Button</SPAN><SPAN class=attr> Content=</SPAN><SPAN class=attrv>"Button"</SPAN> /&gt; &lt;/<SPAN class=tag>ControlTemplate</SPAN>&gt; &lt;/<SPAN class=tag>Setter.Value</SPAN>&gt; &lt;/<SPAN class=tag>Setter</SPAN>&gt; &lt;/<SPAN class=tag>Style</SPAN>&gt; &lt;/<SPAN class=tag>Application.Resources</SPAN>&gt; &lt;/<SPAN class=tag>Application</SPAN>&gt; </pre>&nbsp;</PRE><pre class="prettyprint">But after run (F5) I'm gettin an error: "Invalid attribute value dataprimitives:DataGridColumnHeader for property TargetType. [Line: 9 Position: 54]"</pre><pre class="prettyprint">B.&nbsp;</pre><pre class="prettyprint">&nbsp;</pre> 2008-09-29T13:31:47-04:0099181http://forums.silverlight.net//p/30592/99181.aspx/1?Re+Custom+DataGrid+Header+BUG+in+RC0+Re: Custom DataGrid.Header - BUG in RC0. <p>&nbsp;<span class="attrv">DataGridColumnHeader is in System.Windows.Controls.Primitives name space:<br> </span></p> <p>&nbsp;xmlns:<span class="attr">dataprimitives</span>=&quot;<b>clr-namespace:System.Windows.Controls.Primitives;assembly=System.Windows.Controls.Data</b>&quot;</p> <p>&nbsp;</p> 2008-09-29T14:03:45-04:0099220http://forums.silverlight.net//p/30592/99220.aspx/1?Re+Custom+DataGrid+Header+BUG+in+RC0+Re: Custom DataGrid.Header - BUG in RC0. <p>Of course! It works. Thank you. </p> <p>But&nbsp;my problem still exists. How can I&nbsp;comppose my custom&nbsp;header&nbsp;IN CODE&nbsp;after setting the Style ? The header depends on some parameters. In Beta2 I could do something like that:</p> <p>DataGridTemplateColumn _dgtc = <span class="kwd">new</span> DataGridTemplateColumn();<br> myListHeader lh = <span class="kwd">new</span> myListHeader(); <span class="cmt"> // myListHeader contains the HyperlinkButton</span><br> <br> <span class="kwd">string</span> myHeaderName = <span class="st">&quot;myHeaderName1&quot;</span><br> lh.LayoutRoot.Height = 18;<br> lh.theHyperlinkButton.FontSize = 15;<br> lh.theHyperlinkButton.FontFamily = <span class="kwd">new</span> FontFamily(<span class="st">&quot;Arial&quot;</span>);<br> lh.theHyperlinkButton.Foreground = <span class="kwd">new</span> SolidColorBrush(Colors.Blue);<br> lh.theHyperlinkButton.Content = myHeaderName;<br> <br> _dgtc.Header = lh;<br> <br> </p> It was clear and simple (especially the last line).&nbsp;How can I achieve&nbsp;it in RC?&nbsp; Now I can only set the column header style: _dgtc.HeaderStyle = <font color="#2b91af" size="2"><font color="#2b91af" size="2">Application</font></font><font size="2">.Current.Resources[</font><font color="#a31515" size="2"><font color="#a31515" size="2">&quot;ColumnHeaderStyle&quot;</font></font><font size="2">] </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">as</font></font><font size="2"> </font><font color="#2b91af" size="2"><font color="#2b91af" size="2">Style</font></font><font size="2">;</font><font size="2"> <p>But each my column header is not only the&nbsp;&quot;style&quot; -&nbsp;it can be quite complex (have custom properties, events, ...).&nbsp;</font>I' d like to believe, that I will not have to build custom Header (&quot;myListHeader&quot;) by concatenating it from pieces of&nbsp;XAML strings (simmilarly like CellTemplate/CellEditingTemplate for DataGridTemplateColumn).&nbsp;Please give&nbsp;us back&nbsp;the simplicity of building&nbsp;column header&nbsp;like in&nbsp;Beta2 ! &nbsp;</p> <p>B.</p> <p>&nbsp;</p> 2008-09-29T14:43:51-04:0099223http://forums.silverlight.net//p/30592/99223.aspx/1?Re+Custom+DataGrid+Header+BUG+in+RC0+Re: Custom DataGrid.Header - BUG in RC0. <p>If you have a Template defined in the Style: <br> </p> <p>&lt;Style x:Key=&quot;<font color="#a31515" size="2"><font color="#a31515" size="2">ColumnHeaderStyle</font></font>&quot; TargetType=&quot;primitives:DataGridColumnHeader&quot;&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;Setter Property=&quot;Template&quot;&gt;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;Setter.Value&gt;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;ControlTemplate&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;Button Margin=&quot;5&quot; <b>Content=&quot;{TemplateBinding Content}&quot;</b>&nbsp; HorizontalAlignment=&quot;Center&quot; /&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/ControlTemplate&gt;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/Setter.Value&gt;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/Setter&gt;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/Style&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </p> <p>&nbsp;</p> <p>&nbsp;_dgtc.HeaderStyle = <font color="#2b91af" size="2"><font color="#2b91af" size="2">Application</font></font><font size="2">.Current.Resources[</font><font color="#a31515" size="2"><font color="#a31515" size="2">&quot;ColumnHeaderStyle&quot;</font></font><font size="2">] </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">as</font></font><font size="2"> </font><font color="#2b91af" size="2"><font color="#2b91af" size="2">Style</font></font><font size="2">;</font></p> <p>&nbsp;_dgtc.Header = &quot;YourHeaderText&quot;;&nbsp; // <b>This header text is bind to the Content property of the DataGridColumnHeader, and will be set to your Button.Content property</b><br> </p> <p><br> </p> 2008-09-29T14:53:11-04:0099274http://forums.silverlight.net//p/30592/99274.aspx/1?Re+Custom+DataGrid+Header+BUG+in+RC0+Re: Custom DataGrid.Header - BUG in RC0. <p>It works. Nice.... Thanks. But my case is more complex. This is a piece of code:</p> <p>The custom control &quot;myListHeader&quot;:</p> <p>&lt;<span class="tag">UserControl</span> <br> <span class="attr">&nbsp;&nbsp;&nbsp; x:Class=</span><span class="attrv">&quot;GridHeaderTest.myListHeader&quot;</span><br> <span class="attr">&nbsp;&nbsp;&nbsp; xmlns=</span><span class="attrv">&quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;</span> <br> <span class="attr">&nbsp;&nbsp;&nbsp; xmlns:x=</span><span class="attrv">&quot;http://schemas.microsoft.com/winfx/2006/xaml&quot;</span> <br> &nbsp;&nbsp;&nbsp; &gt;<br> &nbsp;&nbsp;&nbsp; <br> &nbsp;&nbsp;&nbsp; &lt;<span class="tag">StackPanel</span><span class="attr"> x:Name=</span><span class="attrv">&quot;LayoutRoot&quot;</span><span class="attr"> Background=</span><span class="attrv">&quot;Navy&quot;</span><span class="attr"> Orientation=</span><span class="attrv">&quot;Vertical&quot;</span> &gt;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;<span class="tag">HyperlinkButton</span><span class="attr"> x:Name=</span><span class="attrv">&quot;mySortHyperlinkButton&quot;&nbsp;/&nbsp; </span>&gt;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;<span class="tag">TextBox</span><span class="attr"> x:Name=</span><span class="attrv">&quot;myFilterTextBox&quot; </span>/&gt;<br> &nbsp;&nbsp;&nbsp; &lt;/<span class="tag">StackPanel</span>&gt;<br> &nbsp;&nbsp;&nbsp; <br> &lt;/<span class="tag">UserControl</span>&gt;</p> <p>And how to achieve this in RC0 (possible in Beta2):</p> <pre class="prettyprint">DataGridTextColumn _dgtc = <SPAN class=kwd>new</SPAN> DataGridTextColumn(); myListHeader lh = <SPAN class=kwd>new</SPAN> myListHeader(); <SPAN class=kwd>int</SPAN> parameter = 0; lh.mySortHyperlinkButton.Click += <SPAN class=kwd>new</SPAN> RoutedEventHandler(mySortHyperlinkButton_Click); lh.myFilterTextBox.LostFocus += <SPAN class=kwd>new</SPAN> RoutedEventHandler(myFilterTextBox_LostFocus); lh.SizeChanged += (s, e) =&gt; { parameter += 1; <SPAN class=cmt>// for example</SPAN> }; _dgtc.Header = lh; <SPAN class=kwd>void</SPAN> myFilterTextBox_LostFocus(<SPAN class=kwd>object</SPAN> sender, RoutedEventArgs e) { <SPAN class=cmt> // some code</SPAN> } <SPAN class=kwd>void</SPAN> mySortHyperlinkButton_Click(<SPAN class=kwd>object</SPAN> sender, RoutedEventArgs e) { <SPAN class=cmt> // some code </SPAN> }</pre> <p>In other words, how to set&nbsp;PARTICULAR INSTANCE&nbsp;of &quot;myListHeader&quot;&nbsp;(&quot;lh&quot; in this example)&nbsp;with its events&nbsp;(and sometimes parameters sent to the methods serving those events), into&nbsp;THIS PARTICULAR&nbsp;HeaderStyle. I must mention, that columns&nbsp;are created dynamically only&nbsp;(not in xaml).</p> <p>B.&nbsp;</p> <p>&nbsp;</p> <p>&nbsp;</p> 2008-09-29T16:02:31-04:0099278http://forums.silverlight.net//p/30592/99278.aspx/1?Re+Custom+DataGrid+Header+BUG+in+RC0+Re: Custom DataGrid.Header - BUG in RC0. <p>&nbsp;Option1:</p> <p>Hookup button event in the template. But you have to define the header template in UserControl.Resources section instead of Application.Resources. </p> <p>Optoin2:</p> <p>Write a ListHeader UserControl, wrap up all the controls layout and event handler in that UserControl. Then use that UserControl in your DataGridHeaderTemplate. This way you can put the header template in the Application.Resouces.</p> <p>&nbsp;</p> <p>&nbsp;</p> 2008-09-29T16:16:58-04:0099349http://forums.silverlight.net//p/30592/99349.aspx/1?Re+Custom+DataGrid+Header+BUG+in+RC0+Re: Custom DataGrid.Header - BUG in RC0. <p>Thank you. I think, I don't understand what you exactly mean by &quot;wrap up all the controls layout and events ..&quot;. Even if I move&nbsp;all layouts and events of the ListHeader to the UserControl (into separate control in XAML &#43; related code), I will not be able to set my own properties of ListHeader after settin the HeaderStyle. The main problem is that&nbsp;HeaderStyle generates&nbsp;its own instance of the ListHeader and there is no way to update its properties&nbsp;after setting the style. There is no way to set up those properties before setting&nbsp;the HeaderStyle, too.&nbsp;Or ... I don't know how to do it. </p> <p>B.</p> 2008-09-29T17:58:45-04:0099403http://forums.silverlight.net//p/30592/99403.aspx/1?Re+Custom+DataGrid+Header+BUG+in+RC0+Re: Custom DataGrid.Header - BUG in RC0. <p>Here is the code I have tested:</p> <p>1) Create a GridHeader custom control <br> </p> <p>&nbsp;&nbsp;&nbsp; [TemplatePart(Name = GridHeader.HeaderTextElement, Type = typeof(FrameworkElement))] &nbsp;<br> &nbsp;&nbsp;&nbsp; [TemplatePart(Name = GridHeader.FilterTextElement, Type = typeof(TextBox))]&nbsp;&nbsp; &nbsp;<br> &nbsp;&nbsp;&nbsp; public class GridHeader : Control<br> &nbsp;&nbsp;&nbsp; {<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; protected const string HeaderTextElement = &quot;HeaderText&quot;;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; protected const string FilterTextElement = &quot;FilerText&quot;;<br> &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Button header;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; TextBox filterText;<br> <br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #region Constructor<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public GridHeader()<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.DefaultStyleKey = typeof(GridHeader);<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #endregion<br> <br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #region HeaderText<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /// &lt;summary&gt;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /// Identifies the HeaderText dependency property.<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /// &lt;/summary&gt;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public static readonly DependencyProperty HeaderTextProperty = DependencyProperty.Register(&quot;HeaderText&quot;, typeof(string), typeof(GridHeader), null);<br> <br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /// &lt;summary&gt;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /// Gets or sets the HeaderText possible Value of the int object.<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /// &lt;/summary&gt;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public string HeaderText<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; get { return (string)GetValue(HeaderTextProperty); }<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; set { SetValue(HeaderTextProperty, value); }<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #endregion HeaderText<br> <br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #region FilterText<br> <br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /// &lt;summary&gt;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /// Identifies the FilterText dependency property.<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /// &lt;/summary&gt;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public static readonly DependencyProperty FilterTextProperty = DependencyProperty.Register(&quot;FilterText&quot;, typeof(string), typeof(GridHeader), null);<br> <br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /// &lt;summary&gt;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /// Gets or sets the FilterText possible Value of the string object.<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /// &lt;/summary&gt;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public string FilterText<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; get { return (string)GetValue(FilterTextProperty); }<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; set { SetValue(FilterTextProperty, value); }<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #endregion FilterText<br> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public override void OnApplyTemplate()<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; base.OnApplyTemplate();&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.filterText = this.GetTemplateChild(&quot;FilterText&quot;) as TextBox;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.header = this.GetTemplateChild(&quot;HeaderText&quot;) as Button;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if(this.filterText != null)<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.filterText.LostFocus &#43;= new RoutedEventHandler(filterText_LostFocus);<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if(this.header != null)<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.header.Click &#43;= new RoutedEventHandler(header_Click);<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br> &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; void header_Click(object sender, RoutedEventArgs e)<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br> <br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; void filterText_LostFocus(object sender, RoutedEventArgs e)<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br> &nbsp;&nbsp;&nbsp; }</p> <p>&nbsp;Put the following Template in the themes/generic.xaml file<br> </p> <p>&nbsp;&lt;Style TargetType=&quot;controls:GridHeader&quot;&gt;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;Setter Property=&quot;Template&quot;&gt;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;Setter.Value&gt;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;ControlTemplate TargetType=&quot;controls:GridHeader&quot;&gt;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;StackPanel x:Name=&quot;LayoutRoot&quot; Margin=&quot;3&quot; Background=&quot;{TemplateBinding Background}&quot;&gt;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;StackPanel HorizontalAlignment=&quot;Center&quot; Orientation=&quot;Horizontal&quot;&gt;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;TextBlock Text=&quot;{TemplateBinding HeaderText}&quot; /&gt;&nbsp;&nbsp; &lt;!-- if you want default Sort --&gt;<br> </p> <p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; OR</p> <p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &lt;Button Content=&quot;{TemplateBinding HeaderText}&quot; /&gt;&nbsp;&nbsp; &lt;!-- if you want to implement your own Sort --&gt;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;!-- Your can add the Sort indicator image here --&gt;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/StackPanel&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;TextBox Margin=&quot;2&quot; x:Name=&quot;FilterTextBox&quot; Text=&quot;{TemplateBinding FilterText}&quot;/&gt;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/StackPanel&gt;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/ControlTemplate&gt;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/Setter.Value&gt;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/Setter&gt;<br> &nbsp;&nbsp;&nbsp; &lt;/Style&gt; </p> <p>&nbsp;Define Grid-header Style in the app.xaml:<br> </p> <p>&lt;Application.Resources&gt;<br> &nbsp;&nbsp;&nbsp;&nbsp; <br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;Style x:Key=&quot;grid-header&quot; TargetType=&quot;primitives:DataGridColumnHeader&quot;&gt;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;Setter Property=&quot;VerticalAlignment&quot; Value=&quot;Center&quot; /&gt;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;Setter Property=&quot;HorizontalAlignment&quot; Value=&quot;Stretch&quot; /&gt;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;Setter Property=&quot;Template&quot;&gt;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;Setter.Value&gt;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;ControlTemplate&gt;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;my:GridHeader <b>HeaderText=&quot;{TemplateBinding Content}&quot;</b>&nbsp; /&gt;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/ControlTemplate&gt;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/Setter.Value&gt;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/Setter&gt;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/Style&gt;<br> &nbsp;&nbsp;&nbsp; &lt;/Application.Resources&gt; </p> <p>&nbsp;In your code:</p> <p>col.Header = &quot;YourColHeaderText&quot;;&nbsp;</p> <p>col.HeaderStyle =&nbsp; col.HeaderStyle = Application.Current.Resources[&quot;grid-header&quot;] as Style;</p> <p>&nbsp;</p> <p>What I have found for sorting in RC0 DataGrid works differently from beta2:</p> <p>If you want to use Default Sort function, either use default header or define your own header template but do not put a button in the template. This way, when you click the header, the sort would work. If you put a button in the Header template, click that button won't fire default sort. &nbsp; </p> <p>If you defined your own header template, the sort indicator image no longer shows up even sort still work.</p> <p>&nbsp;</p> <p>&nbsp;</p> <p>&nbsp;</p> <p>&nbsp;</p> <p>&nbsp;</p> 2008-09-29T19:21:54-04:0099861http://forums.silverlight.net//p/30592/99861.aspx/1?Re+Custom+DataGrid+Header+BUG+in+RC0+Re: Custom DataGrid.Header - BUG in RC0. <p>Thank you very much! The code is working. I really&nbsp;appreciate your effort! </p> <p>But I think this approach doesn't solve my problem. The final code&nbsp;loks like below:</p> <pre class="prettyprint"><SPAN class=kwd>public</SPAN> Page() { InitializeComponent(); DataGridTextColumn col1 = <SPAN class=kwd>new</SPAN> DataGridTextColumn(); DataGridTextColumn col2 = <SPAN class=kwd>new</SPAN> DataGridTextColumn(); DataGridTextColumn col3 = <SPAN class=kwd>new</SPAN> DataGridTextColumn(); col1.HeaderStyle = Application.Current.Resources[<SPAN class=st>"grid-header"</SPAN>] <SPAN class=kwd>as</SPAN> Style; col2.HeaderStyle = Application.Current.Resources[<SPAN class=st>"grid-header"</SPAN>] <SPAN class=kwd>as</SPAN> Style; col3.HeaderStyle = Application.Current.Resources[<SPAN class=st>"grid-header"</SPAN>] <SPAN class=kwd>as</SPAN> Style; theDataGrid.Columns.Add(col1); theDataGrid.Columns.Add(col2); theDataGrid.Columns.Add(col3); }</pre> <P>Everything works OK with Generic.xaml and style in App.xaml.&nbsp;But I&nbsp;still can't set up properties of the GridHeader BEFORE&nbsp;or AFTER setting the Column Style. I supposed something like that:</P><pre class="prettyprint">&nbsp;<pre class="prettyprint">col1.Header.FilterText = .... <SPAN class=cmt>// in order to take the last column text from db</SPAN> col1.FilterLostFocus += .... <SPAN class=cmt>// in order to store the last column text into db</SPAN> ... col2.Header.FilterText = ... col2.FilterLostFocus += .... ... </pre>&nbsp;</PRE> <p>The &quot;business&quot; problem is that&nbsp;the client wants to&nbsp;store in db&nbsp;the width of the column after changing the size, last&nbsp;&quot;sort order&quot;&nbsp;on the column after changing the sort order and finally the last filter text put into the column header (maby there will be more &quot;needs&quot;&nbsp;in the future ...).&nbsp;</p> <p>B.</p> <p>&nbsp;</p> 2008-09-30T10:41:55-04:00100074http://forums.silverlight.net//p/30592/100074.aspx/1?Re+Custom+DataGrid+Header+BUG+in+RC0+Re: Custom DataGrid.Header - BUG in RC0. <p>Hi,&nbsp; So far I can think of is this: Move the grid_header style (Template) to the UserControl.Resources, then hook up Header_Loaded Event.<br> </p> <p>&lt;UserControl.Resources&gt;<br> &nbsp;&nbsp;&nbsp;&nbsp; <br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;Style x:Key=&quot;grid-header&quot; TargetType=&quot;primitives:DataGridColumnHeader&quot;&gt;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;Setter Property=&quot;VerticalAlignment&quot; Value=&quot;Center&quot; /&gt;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;Setter Property=&quot;HorizontalAlignment&quot; Value=&quot;Stretch&quot; /&gt;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;Setter Property=&quot;Template&quot;&gt;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;Setter.Value&gt;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;ControlTemplate&gt;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;my:GridHeader <b>HeaderText=&quot;{TemplateBinding Content}&quot;</b>&nbsp; <b>Loaded=&quot;Header_Loaded&quot;</b> /&gt;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/ControlTemplate&gt;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/Setter.Value&gt;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/Setter&gt;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/Style&gt;<br> &nbsp;&nbsp;&nbsp; &lt;/UserControl.Resources&gt;&nbsp; </p> <p>&nbsp;</p> <p>private void GridHeader_Loaded(object sender, RoutedEventArgs e)<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; GridHeader h = sender as GridHeader;</p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Check h.HeaderText to know which col you are on, based on that, set the FilterText, and Hookup Event handler (make sure you add the public event in the custom control)<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; h.FilterText = &quot;YourFilterTest&quot;;</p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; h.FilterLostFocus &#43;= ....<br> </p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }&nbsp;&nbsp; </p> <p>Well, I still like the way in beta2 better where we can set the control to the column.Header.&nbsp; Now it's really hard to get access to the controls defined in template ( a cross-board issue for getting access to the controls in template in Silverlight). </p> <p>&nbsp;</p> 2008-09-30T16:13:47-04:00100802http://forums.silverlight.net//p/30592/100802.aspx/1?Re+Custom+DataGrid+Header+BUG+in+RC0+Re: Custom DataGrid.Header - BUG in RC0. <p>Good idea. The problem is that this &lt;UserControl.Resources&gt; in my case shoul be inside the XAML control of <strong>DataGridTemplateColumn</strong>. I don't know yet how to create the&nbsp;XAML file&nbsp;for DataGridColumn type&nbsp;because at present each my DataGridTemplateColumn&nbsp;is created in code, without XAML. On the other hand, a simple creation of the XAML control &quot;myDataGridTemplateColumn&quot; doesn't work, because UserControl type&nbsp;cann't be added as a&nbsp;<strong>Column</strong>: &quot;DataGrid.Columns.Add(myDataGridTemplateColumn)&quot;.&nbsp; And (of course...)&nbsp;the base class of&nbsp;&quot;myDataGridTemplateColumn&quot; can't be a DataGridColumn type&nbsp;(must be &quot;UserControl&quot;).&nbsp;Thank you for all your help! </p> <p>B.</p> 2008-10-01T15:25:39-04:00100809http://forums.silverlight.net//p/30592/100809.aspx/1?Re+Custom+DataGrid+Header+BUG+in+RC0+Re: Custom DataGrid.Header - BUG in RC0. <p>The more I play with this, the more I think the design change for how to set col header in RC0 is flawed, unless I haven't found the correct way to do this. </p> <p>The DataGridColumn.Header property is still Object type (just like in beta2), but you can not set anything other than the header text string to it which I think is wrong.<br> </p> <p>I even wrote a custom Header that inherited from DataGridColumnHeader object, but there is no way for me to set it to the DataGridColumnHeader._headerCell to replace the original DataGridColumnHeader object which is set internally.<br> </p> <p>I wrote a request in another thread asking this question. Hope someone from Microsoft can answer it.<br> </p> <p>You can follow that thread: <a href="/forums/t/30731.aspx" title="http://silverlight.net/forums/t/30731.aspx"> http://silverlight.net/forums/t/30731.aspx </a></p> <p>&nbsp;</p> <p>&nbsp;</p> <p><br> </p> 2008-10-01T15:43:37-04:00100820http://forums.silverlight.net//p/30592/100820.aspx/1?Re+Custom+DataGrid+Header+BUG+in+RC0+Re: Custom DataGrid.Header - BUG in RC0. <p>It's nice to hear somebody supports me. I've written the &quot;suggestion&quot; in another thread, too (<a href="http://silverlight.net/forums/p/31442/99361.aspx">http://silverlight.net/forums/p/31442/99361.aspx</a>) but&nbsp;there is no answer. After your suggestion of &quot;Loaded&quot; event&nbsp;I've&nbsp;also tried to find &quot;Parent&quot; of my GridHeader in&nbsp;order to&nbsp;find the DataGridHeader, but the code: </p> <pre class="prettyprint"> <SPAN class=kwd>void</SPAN> myListHeader_Loaded(<SPAN class=kwd>object</SPAN> sender, RoutedEventArgs e) { <SPAN class=kwd>object</SPAN> obj = ((myListHeader)sender).Parent; }</pre> <p>&nbsp;&nbsp;&nbsp;gives null. </p> <p>My&nbsp;next idea&nbsp;was to find the&nbsp;myHeader&nbsp;inside the&nbsp;HeaderStyle.Setters collection or sth, but with no effect, too. </p> <p>In my opinion, the present type of using DataGrid.Header is completly useless&nbsp;when you want to make headers from code. </p> <p>Thanks for the link. I'm interested in every information about this subject. </p> <p>B.</p> 2008-10-01T16:06:34-04:00101414http://forums.silverlight.net//p/30592/101414.aspx/1?Re+Custom+DataGrid+Header+BUG+in+RC0+Re: Custom DataGrid.Header - BUG in RC0. <p>For finding Parent for any control, you now need to use VisualTreeHelper.GetParent function instead of control.Parent property. Try that and see if you get the parent of the header. <br> </p> 2008-10-02T13:29:15-04:00101485http://forums.silverlight.net//p/30592/101485.aspx/1?Re+Custom+DataGrid+Header+BUG+in+RC0+Re: Custom DataGrid.Header - BUG in RC0. <p>Thanks for advice. Here is the tree of DataGridColumnHeader parents:</p> <pre class="prettyprint">DataGridColumnHeader obj = (DataGridColumnHeader)VisualTreeHelper.GetParent(<SPAN class=kwd>this</SPAN>); DataGridColumnHeadersPresenter obj1 = (DataGridColumnHeadersPresenter)VisualTreeHelper.GetParent(obj); Grid obj2 = (Grid)VisualTreeHelper.GetParent(obj1); Border obj3 = (Border)VisualTreeHelper.GetParent(obj2); DataGrid obj4 = (DataGrid)VisualTreeHelper.GetParent(obj3);</pre><pre class="prettyprint">The problem is that the DataGridColumn of that header takes place in property "OwningColumn" (of the obj in this example) which is "Non-Public member".</pre><pre class="prettyprint">B. </pre> 2008-10-02T15:08:50-04:00