Hi,
Please find attached a simple project demonstrating strange behaviour with setting the "Generic" theme.
We have a base class that inherits from XamDataGrid. In here I set the active theme in code and to keep it simple, bind to sample data for this demo. I then use a copy of this new control within a window.
As you can see, the height of all the rows has become squashed, meaning you can't even see the headers.
I found that if I also set Theme="Generic" in the window in which my derived control is situated, all works ok.
I don't want to have to specify the theme on every instance of my control being used, I just want to set it in the base class so any changes here would apply globally.
Regards,
Dave
Hi Alex,
No problem :-) Good point... I hadn't thought about using the Loaded event instead.
It does indeed work if you move either of the two lines into the Loaded event. We also know that specifying the Theme in Doc1.xaml makes it work. I found it also works if you leave the two lines in the Initialized event and add the following few lines to the Loaded event:
Dim theme As String = Me.Theme
Me.Theme = String.Empty
Me.Theme = theme
So, by making it think it's changing theme, also works. The one thing all these methods have in common, is they force the grid to redraw after the Loaded event occurs.
I think this is a bug. I believe it *should* be laying out the visuals correctly without using any of the above workarounds. Something must be happening after the Initialized event, that is vital to the measure/arrange phase. If it were not technically possible to set the theme and bind to data before the Loaded event occurs, I would expect it to throw an exception to notify you of the fact.
Also, the reason you only see the headers squashed and not the data rows, I expect, is down to you running it on Vista. I'm running XP, but have just run it on a Vista box and it only affects the headers.
I have also come across this. I have a user control that contains a xamDataGrid. Within this user control, I reference a theme that I have created for the grid as a resource, and the datagrid uses this theme no problem when the usercontrol is loaded into my main application window.
However if I open a dialog window, with the usercontrol loaded into it, then I start to get strange issues with the row heights on certain rows but not all.
Usercontrol in main application window.
User control in secondary window shown as dialog.
As you can see, the row heights are much smaller than in the main window, and randomly, the text is sometimes not positioned correctly.
I have managed to get around this by referencing the theme namespace in the dialog window which seems to get it all to work, but am I missing something, as I assumed that because the usercontrol itself (which has the data grid as a child element) has reference to the theme namespace, the parent window wouldn't need this?
Dave,
And thanks for providing a sample once again. It's really easy and fast to reproduce/suggest a solution when we have a sample to work with right away.
Hello Dave,
I am assuming that the Initialized event is too early for this. You can try with the Loaded and FieldLayoutInitialized, which are fired after Initialized event and it should work correctly. I was able to reproduce only the header incorrect size and not the records incorrect size. Please try with these events and let us know if it solves this issue?