I have a WPF user control for which I need to force rendering in RenderMode.SoftwareOnly
. Since I am using .NET 3.5, I had to do something like this:
var hwndSource = PresentationSource.FromVisual(this) as HwndSource;
if (hwndSource != null)
{
hwndSource.CompositionTarget.RenderMode = RenderMode.SoftwareOnly;
}
But this is not working on my application, The WPF program is crashing on few machines and turning off the hardware acceleration at the registry level seems to fix the issue.
The above code is written in the Loaded
event of the window. If I am correct, Loaded
event happens after the controls are rendered (MSDN). So does it make sense to have the above code in that event? If not, which event would be appropriate for it?
Also, will setting RenderMode
on a visual affects its children? Or do I need to set this specifically for each child elements?