Is it possible to access the grid header programatically?
-
4 августа 2012 г. 6:54
I know it's possible to access a grid's column headers by:
this.FindControl("grid").ControlAvailable += (s, e) => { (e.Control as System.Windows.Controls.DataGrid. .... };
Of course it's also possible to access the displayname of the grid: this.FindControl("grid").Displayname,
but I want to have access to the header control of the grid (not the columns) as indicated by following screenshot:
Is that possible? How?
thx
paul van bladel
Все ответы
-
4 августа 2012 г. 18:11
I'm sorry, I should have posted this question in the general forum not the extensibility forum. I presume the moderator can move the question.
paul van bladel
-
5 августа 2012 г. 8:16
Hello Paul,
Yes, it is possible, see post Grid - No Header?, there is a code sample how do set the grid header to invisible.
All elements are somewhere in the VisualTree, the only difficult point is to find them.
Olaf Helper
* cogito ergo sum * errare humanum est * quote erat demonstrandum *
Wenn ich denke, ist das ein Fehler und das beweise ich täglich
Blog Xing- Изменено Olaf HelperMicrosoft Community Contributor 5 августа 2012 г. 8:16
- Помечено в качестве ответа Paul Van Bladel 5 августа 2012 г. 9:17
-
5 августа 2012 г. 9:20
Hi Olaf,
Thanks for that.
I presume you use XamlSply to figure out things like this?
With some additional patching on the dataGrid itself, you can get things like (with the shadow):
this.FindControl("grid").ControlAvailable += (s, e) => { Control baseControl = e.Control as Control; Border border = baseControl.Parent as Border; Grid parentGrid = border.Parent as Grid; Grid grandParentGrid = parentGrid.Parent as Grid; grandParentGrid.Children[0].Visibility = System.Windows.Visibility.Collapsed; //header grandParentGrid.Children[1].Visibility = System.Windows.Visibility.Collapsed; //command and search bar DataGrid dataGrid = baseControl as DataGrid; dataGrid.GridLinesVisibility = System.Windows.Controls.DataGridGridLinesVisibility.None; dataGrid.HeadersVisibility = System.Windows.Controls.DataGridHeadersVisibility.None; dataGrid.Effect = new System.Windows.Media.Effects.DropShadowEffect(); };
paul van bladel

