Why do WPF Applications look different between Windows 7 and Windows 8 and can this be fixed?

前端 未结 4 464
無奈伤痛
無奈伤痛 2021-01-31 10:13

I\'m really surprised that this question does not appear to have been asked yet... if it has, but I just couldn\'t find it, apologies.

Ok, so my work computer has just b

4条回答
  •  滥情空心
    2021-01-31 10:54

    The problem (as described in other answers) is that WPF picks a default theme determined by the operating system version.

    You need to override this behavior. THIS ARTICLE describes how:

    WPF comes with a few theme assemblies, one for each Windows theme (Luna, Royale and Aero and the fallback theme, Classic.) Usually the theme is loaded according to your current system theme, but if you want to create a consistent look for your application, you may want to force-load a specific one.

    To accomplish that, simply add the following code in your Application Startup event (this example shows how to use the Aero theme):

    Uri uri = new Uri(“PresentationFramework.Aero;V3.0.0.0;31bf3856ad364e35;component\\themes/aero.normalcolor.xaml”, UriKind.Relative);
    
    Resources.MergedDictionaries.Add(Application.LoadComponent(uri) as ResourceDictionary); 
    

    It’s important to specify the version and the public key token. Otherwise you’ll have to copy the theme assembly to the folder of your executable. The reason I’m adding it to the merged dictionaries collection is that I don’t want to lose other resources I added to the App.xaml file.

提交回复
热议问题