c# - Software rendering mode - WPF -
i have wpf user control need force rendering in rendermode.softwareonly
. since using .net 3.5, had like,
var hwndsource = presentationsource.fromvisual(this) hwndsource; if (hwndsource != null) { hwndsource.compositiontarget.rendermode = rendermode.softwareonly; }
but not working on application, wpf program crashing on few machines , turning off hardware acceleration @ registry level seems fix issue.
the above code written in loaded
event of window. if correct, loaded
event happens after controls rendered (msdn). make sense have above code in event? if not, event appropriate it?
also, setting rendermode
on visual affects it's children? or need set each child elements?
any great!
here's did:
private void window_loaded(object sender, routedeventargs e) { if (forcesoftwarerendering) { hwndsource hwndsource = presentationsource.fromvisual(this) hwndsource; hwndtarget hwndtarget = hwndsource.compositiontarget; hwndtarget.rendermode = rendermode.softwareonly; } }
it worked ok us, except... needs done every window. in .net 3.5 there no way make setting take effect application-wide. , there windows won't have control on - example, right-click "context" windows. found there no solution .net 3.5 except registry setting.
edited
here's logic used determine when force software rendering. suggested microsoft support engineer.
public bool forcesoftwarerendering { { int renderingtier = (system.windows.media.rendercapability.tier >> 16); return renderingtier == 0; } }
in .net 4 microsoft added application-wide setting works us. better option because don't need set on every window. set once , applies windows.
edited
the new .net 4.0 property can set @ application startup this:
public partial class app : application { protected override void onstartup(startupeventargs e) { if (forcesoftwarerendering) renderoptions.processrendermode = rendermode.softwareonly; } }
Comments
Post a Comment