I want to style the header for another control in my app to the same header that's used by the XamDataGrid. The XamDataGrid's header can change depending on whether my app is running under Windows XP or Vista so I don't think I can just hardcode a style.
I've used Snoop and found that the header is an igWindows:CardPanel with a name of SpacerFill. But at this point I'm kind of lost on how to actually get at that object. Any help would be appreciated.
I figured out a way to do this. It involves more code than I thought I'd need, but it works. I ended up having to recreate the XAML structure myself and had code like this:
After that I had to use some C# code to walk the visual tree of the document until I found the SpacerFill element in the XamDataGrid.
DependencyObject target; int childCount = VisualTreeHelper.GetChildrenCount(current);
for(int i = 0; i < childCount; i++) { target = this.WalkTree(VisualTreeHelper.GetChild(current, i), match); if(target != null) return target; }
return null;}
private void Window_Loaded(object sender, RoutedEventArgs e) { Panel panel = this.WalkTree(this.xamDataGrid1, o => o.GetValue(NameProperty).Equals("SpacerFill")) as Panel;
if(panel != null) { ((Rectangle) this.headerGrid.Children[0]).Fill = ((Rectangle) panel.Children[0]).Fill; ((Rectangle) this.headerGrid.Children[1]).Fill = ((Rectangle) panel.Children[1]).Fill; ((Rectangle) this.headerGrid.Children[2]).Fill = ((Rectangle) panel.Children[2]).Fill; }}
BTW, I'm using Visual Studio 2008 so I could use lambda expressions from C# 3.0 in the first line of my Window_Loaded method. Helps allow the WalkTree method to be more reusable.