I'm using System.Windows.MessageBox in a WPF app, and for some reason its buttons are styled the Windows 2000 way - not WinXP, not Aero, not the WPF default. Just gray with basic 3d borders.
How can I make them appear with a more modern style? (doesn't really matter which one)
You can fix this with a manifest. See this article for step-by-step instructions: Why am I Getting Old Style File Dialogs and Message Boxes with WPF
Basically, you have to add an XML file called a 'manifest' to your application.
Update:
Actually, it is very easy to do this in VS2008. Go to Project Properties->Application and click the 'View UAC Settings' button. This will automatically create an application manifest file and open it. Edit this file as follows:
Just after the line:
</trustInfo>
Paste in the following dependency section:
<!-- Activate Windows Common Controls v6 usage (XP and Vista): -->
<dependency>
<dependentAssembly>
<assemblyIdentity
type="win32"
name="Microsoft.Windows.Common-Controls"
version="6.0.0.0"
processorArchitecture="*"
publicKeyToken="6595b64144ccf1df"
language="*"
/>
</dependentAssembly>
</dependency>
My complete manifest looks like this:
<?xml version="1.0" encoding="utf-8"?>
<asmv1:assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1" xmlns:asmv1="urn:schemas-microsoft-com:asm.v1" xmlns:asmv2="urn:schemas-microsoft-com:asm.v2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<assemblyIdentity version="1.0.0.0" name="MyApplication.app"/>
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
<security>
<requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
<!-- UAC Manifest Options
If you want to change the Windows User Account Control level replace the
requestedExecutionLevel node with one of the following.
<requestedExecutionLevel level="asInvoker" uiAccess="false" />
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
<requestedExecutionLevel level="highestAvailable" uiAccess="false" />
If you want to utilize File and Registry Virtualization for backward
compatibility then delete the requestedExecutionLevel node.
-->
<requestedExecutionLevel level="asInvoker" uiAccess="false" />
</requestedPrivileges>
</security>
</trustInfo>
<!-- Activate Windows Common Controls v6 usage (XP, Vista, Win 7) to support themed dialogs: -->
<dependency>
<dependentAssembly>
<assemblyIdentity
type="win32"
name="Microsoft.Windows.Common-Controls"
version="6.0.0.0"
processorArchitecture="*"
publicKeyToken="6595b64144ccf1df"
language="*"
/>
</dependentAssembly>
</dependency>
</asmv1:assembly>
After doing this, just build your app, run, and voila, the MessageBox dialog buttons take on the system theme style.
Related
I'm building my Windows app with MinGW:
windres app.rc -O coff -o app.res
gcc -w -mwindows -o app.exe app.c app.res
Here's my app.exe.manifest:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity
version="1.1.0.0"
processorArchitecture="x86"
name="controls"
type="win32"
/>
<dependency>
<dependentAssembly>
<assemblyIdentity
type="win32"
name="Microsoft.Windows.Common-Controls"
version="6.0.0.0"
processorArchitecture="*"
publicKeyToken="6595b64144ccf1df"
language="*"
/>
</dependentAssembly>
</dependency>
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
<security>
<requestedPrivileges>
<requestedExecutionLevel
level="asInvoker"
uiAccess="false"
/>
</requestedPrivileges>
</security>
</trustInfo>
<asmv3:application>
<asmv3:windowsSettings xmlns="http://schemas.microsoft.com/SMI/2017/WindowsSettings">
<gdiScaling>true</gdiScaling>
</asmv3:windowsSettings>
</asmv3:application>
</assembly>
I do this to enable Windows 10's new GDI scaling. It works fine until I move my executable to a different location.
Surprisingly, copying the entire directory doesn't help, so the system doesn't need the manifest or the resource file. The path seems to be hardcoded somewhere.
How can I fix this?
Thanks
Turned out my manifest was bad. It didn't include the xmlns:asmv3 parameter
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" xmlns:asmv3="urn:schemas-microsoft-com:asm.v3" manifestVersion="1.0">
I am trying to perform a build on a WPF (.Net Framework 4.0) project using the Microsoft.Build assemblies, i.e. not building from VS and not building using stock standard MSBuild from command line. All my projects build successfully, but the WPF project fails with the following message:
C:\WINDOWS\Microsoft.NET\Framework64\v4.0.30319\Microsoft.WinFx.targets(268,9): error MSB4127: The "MarkupCompilePass1" task could not be instantiated from the assembly "PresentationBuildTasks, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35". Please verify the task assembly has been built using the same version of the Microsoft.Build.Framework assembly as the one installed on your computer and that your host application is not missing a binding redirect for Microsoft.Build.Framework. Unable to cast object of type 'Microsoft.Build.Tasks.Windows.MarkupCompilePass1' to type 'Microsoft.Build.Framework.ITask'. [C:\Service\Test.csproj]
C:\WINDOWS\Microsoft.NET\Framework64\v4.0.30319\Microsoft.WinFx.targets(268,9): error MSB4060: The "MarkupCompilePass1" task has been declared or used incorrectly, or failed during construction. Check the spelling of the task name and the assembly name.
I have found references (on Stack Overflow) mentioning the updated MSBuild assemblies (12.0 vs 4.0) etc etc. This has all been updated, i.e. references from the build utility, but no luck.
Any ideas/suggestions?
We are using a similar system and the problem seems to stem from the compilation of the Page tag: <generator>MSBuild:Compile</generator>. This seems to be invoking MSBuild in a way that pulls the 4.0 framework libraries.
For our build executable, we simply modified the configuration to include the configurations used by the 12.0 MSBuild configuration. i.e., take the elements in C:\Program Files (x86)\MSBuild\12.0\bin\MSBuild.exe.config and place them in your application configuration. This resolved the issues for us.
I found a solution. Add a binding redirect to the version you want to use in your App.config:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
</startup>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Microsoft.Build.Framework" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-99.9.9.9" newVersion="15.1.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Build.Framework" culture="neutral" publicKeyToken="b03f5f7f11d50a3a" />
<bindingRedirect oldVersion="0.0.0.0-99.9.9.9" newVersion="15.1.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Build" culture="neutral" publicKeyToken="b03f5f7f11d50a3a" />
<bindingRedirect oldVersion="0.0.0.0-99.9.9.9" newVersion="15.1.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
In a .NET 4.5 Winforms app and using the exact code from the PayPal API doc I'm getting:
"Cannot parse *.Config file. Ensure you have configured the 'paypal' section correctly."
I'm just posting the line that causes this:
OAuthTokenCredential tokenCredential = new OAuthTokenCredential("xxxxxxxxxxxxxx", "xxxxxxxxxx");
Any ideas how to proceed?
Thanks
Since Steve chose to be obtuse, for the sake if anyone else having this issue, here is the link to a similar question which solved my problem. Might be my lack of experience working with app.config files but I had to be sure to insert the code as the first entries in the file or my HttpClient class failed on startup.
Link that put me on the right path:
Paypal c# REST API asks for an undocumented configuration section
My App.config file (basic App.config file from a new VS2013 WinForms project after adding the NuGet PayPal REST SDK Package and the parts from the solution from the link above)
As mentioned on the link as well, aaa, bbb, ccc, ddd are from your sandbox account profile.
<configSections>
<section name="paypal" type="PayPal.Manager.SDKConfigHandler, PayPalCoreSDK"/>
</configSections>
<paypal>
<accounts>
<account apiUsername="aaa"
apiPassword="bbb"
applicationId="ccc"
apiSignature="ddd"/>
</accounts>
<settings>
<add name="mode" value="sandbox"/>
</settings>
</paypal>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
Does anyone know why the application manager, found by going to settings->application manager, is showing the wrong name for my application? I installed my app twice under different names and with different application package names. I can see both named applications under the apps page, but the application manager is showing them as the same name. I need to know which is which so I can force close and uninstall the correct version of my application. Any ideas?
Here's the manifest of the DEMO version of my application, where string/app_name = package_DEMO:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="my.apps.package_DEMO"
android:versionCode="1"
android:versionName="0.0">
<uses-sdk
android:minSdkVersion="10"
android:targetSdkVersion="10"/>
<application android:label="#string/app_name"
android:name="my.apps.package.MyApplication"
android:icon="#drawable/ic_launcher"
android:theme="#style/AppTheme"
android:launchMode="singleTask"
android:debuggable="true">
<activity android:label="#string/app_name"
android:configChanges="orientation|keyboardHidden"
android:name="my.apps.package.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:label="#string/app_name"
android:configChanges="orientation|keyboardHidden"
android:name="my.apps.package.SettingsActivity">
</activity>
</application>
</manifest>
And the original's manifest, where string/app_name = package:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="my.apps.package"
android:versionCode="1"
android:versionName="0.0">
<uses-sdk
android:minSdkVersion="10"
android:targetSdkVersion="10"/>
<application android:label="#string/app_name"
android:name="my.apps.package.MyApplication"
android:icon="#drawable/ic_launcher"
android:theme="#style/AppTheme"
android:launchMode="singleTask"
android:debuggable="true">
<activity android:label="#string/app_name"
android:configChanges="orientation|keyboardHidden"
android:name="my.apps.package.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:label="#string/app_name"
android:configChanges="orientation|keyboardHidden"
android:name="my.apps.package.SettingsActivity">
</activity>
</application>
</manifest>
I had this problem - i.e. that of the app name showing up incorrectly in Settings->Apps
I managed to fix it by rebooting the device.
My guess is that the android application manager was caching the 'old' name until a reboot. I confirmed this by changing the app name and redeploying - the old name shows in settings->aps until a reboot.
It is probably because of your manifest file. If you copied your code and only refactored the package names, eclipse does not change the name of your application in the manifest file.
Either change directly, or use your string.xml files
android:label="#string/app_name"
you can add android:label="YOUR NAME APP"
<application
android:label="YOUR NAME APP"
android:allowBackup="true"
android:icon="#drawable/logo">
You can uninstall the package name by connecting your phone to the pc...
Go to the command prompt
adb uninstall packagename
so if you want to delete an an app with package name com.example.test
Type : adb uninstall com.example.test in command prompt...
Note :
adb should in the system path
or else run this command from your sdkfolder/platform-tools/
I just uninstalled, cleaned, and reinstalled for like the 50th time, and magically the app names are different under the application manager. This must be a system bug, because both versions of the app were showing different names in the activity labels, and under the "apps" page on the device eariler. I'll try seeing if I can reproduce it again.
I have a problem where I compiled my application on Visual Studio 2010 while targetting the .NET Framework 3.5, deployed it to a client server, only to find it gives me the following error:
************** Exception Text **************
System.MissingMethodException: Method not found: 'Void
System.Xml.Xsl.XslCompiledTransform.Transform(
System.Xml.XPath.IXPathNavigable,
System.Xml.Xsl.XsltArgumentList,
System.Xml.XmlWriter,
System.Xml.XmlResolver)'.
************** Loaded Assemblies **************
[...]
System.Xml
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.3082 (QFE.050727-3000)
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Xml/2.0.0.0__b77a5c561934e089/System.Xml.dll
The method it says it's looking for is this: XslTransform.Transform Method (IXPathNavigable, XsltArgumentList, XmlWriter, XmlResolver) (Supported in: 4, 3.5, 3.0, 2.0, 1.1)
I've tried setting up a redirect to the .NET Framework 4.0 version of the same DLL using the assemblyBinding element like so:
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Xml"
publicKeyToken="b77a5c561934e089"
culture="neutral" />
<bindingRedirect oldVersion="2.0.0.0"
newVersion="4.0.0.0"/>
<codeBase version="4.0.0.0"
href="file:///C:/WINDOWS/Microsoft.NET/assembly/GAC_MSIL/System.Xml/v4.0_4.0.0.0__b77a5c561934e089/System.Xml.dll" />
</dependentAssembly>
</assemblyBinding>
</runtime>
But now the application won't run, and puts this in the event log:
EventType clr20r3, P1
myapplication.exe, P2 3.85.12.27583,
P3 4be9757f, P4 system.configuration,
P5 2.0.0.0, P6 4889de74, P7 1a6, P8
136, P9
ioibmurhynrxkw0zxkyrvfn0boyyufow, P10
NIL.
So, in summary, (1) does anyone know why the application can't find the method listed, and (2) why doesn't it let me redirect to the .NET 4.0 version of System.Xml?
Any help is appreciated, I'm totally stuck!
app.config as requested:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v2.0.50727"/>
</startup>
<configSections>
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<section name="myapplication.Properties.UserSettings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
</sectionGroup>
</configSections>
<system.net>
<mailSettings>
<smtp from="e-monitoring#myapplication.co.uk">
<network defaultCredentials="true" host="192.168.0.132" port="25" password="" userName="" />
</smtp>
</mailSettings>
</system.net>
<appSettings file="">
<add key="ReportDataCollectionTimeout" value="360" />
<add key="AllowedDatabaseBuild" value="3" />
<add key="AllowedDatabaseRevision" value="085" />
<add key="HelpNamespace" value="myapplicationHelpfile.chm" />
<add key="ProFormaHomePageUri" value="https://myapplication.co.uk/" />
<add key="ProFormaLoginPageUri" value="https://myapplication.co.uk/login.aspx" />
</appSettings>
<connectionStrings configSource="connectionStrings.config" />
<userSettings>
<myapplication.Properties.UserSettings>
<setting name="RequiresUpgrade" serializeAs="String">
<value>True</value>
</setting>
</myapplication.Properties.UserSettings>
</userSettings>
</configuration>
If you are targeting .NET 3.5 why are you doing a binding redirect to System.Xml v4.0.0.0? Make sure that your project references v2.0.0.0 of that assembly and that you have the following in your app.config:
<startup><supportedRuntime version="v2.0.50727"/></startup>
Also make sure that you are targeting .NET Framework 3.5 and not .NET Framework 3.5 Client Profile. Finally make sure the client has .NET 3.5 installed.
I've solved the problem by using this Transform method instead of the previous one (where I was previously passing null into the XmlResolver argument at the end).
Strange how this worked on my development and test machine, and not the server.
Try looking into the file version for System.XML.dll in the assembly folder. chances are that the last bit of the file on your system are different then the ones on server. in your case "2.0.50727.3082" does not seem to have the specified method signature. The version on the development machine was "2.0.50727.8009" which did have the required method signature.
EDIT: Decided to use the XMLReader version of the method. Even though we could register the newer version in the GAC(which did'nt give runtime error) from our local machine and that removed the error. but since the .NET could upgrade to a newer version and overwrite GAC we would need to be careful that the newer version would not have same problem.