.NET4.0 WPF issue on rendering on XP SP3 box
All is fine and dandy on my Win 7 x64 based system running an app built in .NET4.0. However, not so good on the XP SP3 box. Rendering seems to be an issue. Borders are appearing where I dont want them to and dynamically populated items in ItemsControl are switching between values in a combobox! Following is what I have tried so far.
Ive been going through this question and tried to debug further.
- Turn off hardware acceleration off on the desktop properties. (didnt seem to make any difference)
- Add registry entry to turn off hardware acceleration (didnt seem to make any difference)
Add the following code on MainWindow.Xaml.Cs:
protected override void OnSourceInitialized(EventArgs e) { var hwndSource = PresentationSource.FromVisual(this) as HwndSource; if (hwndSource != null) { hwndSource.CompositionTarget.RenderMode = RenderMode.SoftwareOnly; _log.Debug("success开发者_StackOverflow社区fully set render mode to software");
_log.Debug("WPF Tier = {0}", RenderCapability.Tier / 0x10000); } base.OnSourceInitialized(e); }
Log shows that the Tier is 0. This XP SP3 box seems to have DirectX 9.0c. 4. Added the following code to App.xaml.cs:
protected override void OnStartup(StartupEventArgs e)
{
RenderOptions.ProcessRenderMode = RenderMode.SoftwareOnly;
}
Im not sure what else to try. Any assistance is welcome!
Thanks,
I believe Ive got the answer (at least a solution : )). Two things were bugging me about the whole thing.
- Borders around
ComboBox
items when they didnt need to be there - Values in dynamically bound
ComboBox
items flickering. Ie "ASDFASDF" would flick between "ASDF" and "ASDFASDF".
To fix item 1, I took out the Border
style definition in App.xaml file. Individually define Border
properties on each tag. I'll have to look further into this issue.
As for item 2, I was using the UniformWrapPanel
code from this article. This seems to be calling protected override Size MeasureOverride(Size availableSize)
constantly and not only does it slow things down but also not sure about how to best render the contents within a ComboBox. In the end I defined the widest Width
property I could think of but will most likely end up binding to a property in View-Model. I have to figure out how to determine a Width based on font size and the length of characters to fit in.
I hope this would help some one : )
Cheers,
精彩评论