I'm trying to detect nearby devices using NFC or RFID from within a WPF application.
Microsoft's proximity API seems to be the right way to go:
http://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh465221.aspx
Unfortunately, I see no way to get it running inside a WPF application (or any other Desktop Technology that is). All examples refer to Microsoft store apps only.
From within a WPF application I cannot reference the Namespace
using Windows.Networking.Proximity;
Is it just a reference that I am missing? Is it possible to use the proximity API from a WPF application at all?
I finally found a sample project using the proximity API from within a WPF application:
http://code.msdn.microsoft.com/windowsdesktop/NFC-Editor-529ccda6
There is also a short tutorial included on how to use WinRT API's in WPF applications.
The basic steps:
Manually add a <TargetPlatformVersion>8.0</TargetPlatformVersion> line to the csproj file
Back in Visual Studio, add a reference to Windows/Core/Windows to the project references
Add a reference to the Windows Runtime assemblies to the project.
See above given link for details.
I believe that the Windows.Networking.Proximity.ProximityDevice class is not available in WPF Applications. If you look on the ProximityDevice class page on MSDN, you'll see that it is part of the Windows.Phone API:
The monitor image next to the phone image also leads me to believe that it is available for Windows Store Apps too. I'm guessing that (at present at least) the vast majority of desktop computers won't have any RFC hardware that could be used with this code and so that is why it is missing from the standard .NET dlls.
[2020 is here]
Procedure to prepare your Console/WPF project to call UWP APIs (both are OK):
https://learn.microsoft.com/en-us/windows/apps/desktop/modernize/desktop-to-uwp-enhance
https://blogs.windows.com/windowsdeveloper/2019/09/30/windows-10-winrt-api-packs-released/
Heads up: You'll need to migrate the project from the packages.config management format to the PackageReference format
https://learn.microsoft.com/en-us/nuget/consume-packages/migrate-packages-config-to-package-reference#migration-steps
Related
Does anybody of you guys have experiences with including a C#-based Console Application in a C#-based Universal Windows App?
The reason why I'm asking: I've an already exsisting Console Application developed by another developer. This Application includes a database with all the queries which I need for my App.
The problem: When I try to include the CA in my UWA project many commands like
private global::System.Runtime.InteropServices.HandleRef
throw new global::System.ApplicationException
don't get identified by VS2015.
Is there a way to let the UWA project identify CA commands? For example with adding an external CA-library or something like that.
Thank you!
You can't combine full .NET (console, winforms, WPF) assemblies with an UWP app, as they're different .NET frameworks. For more details, please read this reply. Part of the code is shareable in a Portable Class Library (PCL), but most likely not all of the code you've written.
Possible solutions:
Create an API (yourself or with the other developer) to expose the functionality needed over a (preferably) REST api.
Find a way to cheat the system. Example: launch a file (associated to the console application) with the Launcher api and output the results to a text file on disk, which you then read from your UWP app.
The first one is guaranteed to work. You might find a way to cheat the system for the second 'solution', but there's no guarantee that it won't break in the future when Windows 10 gets updated (experienced that myself for another 'hack' on the upgrade between Windows 8 and 8.1).
One example would be the new notification APIs for Windows 10 universal platform. Can I use this set of APIs in a WPF app? If so are there any limitations?
Links to documentation regarding this would be much appreciated.
It is possible to use UWP APIs in a WPF app. However not all UWP APIs can be used in a WPF app.
There are exceptions to the rule that Windows 10 APIs are accessible from PC software. The first big exception concerns XAML UI APIs. The XAML framework in UWP is different from the one in WPF and you really don’t want to be mixing them up, anyways.
The second set of APIs that you can’t use are ones that depend on an app’s package identity. UWP apps have package identities while PC software does not. Package identity information can be found in the app manifest file.
How do you determine which Windows 10 APIs require a package identity and which do not? The easiest way is to refer to this MSDN topic.
For how to access the Windows 10 APIs from WPF, please refer to this answer and also see the blog Calling Windows 10 APIs From a Desktop Application (Please note the name of the references in the blog is not right, so I'd suggest you refer the answer in SO).
No, You can't - at least for now -
But there's a progress on a project called "Centennial" Which will enable you to do so.
More see "bridges".
Yes, you can now.
https://blogs.windows.com/buildingapps/2017/01/25/calling-windows-10-apis-desktop-application/
I tried to use the SpeechSynthesizer from System.Speech.Synthesis because it seems more comprehensive than the one I used before (Windows.Media.SpeechSynthesis) : I want to be able to set the volume, the gender of the voice, ... Besides, the french prononciation has some bugs, so I wanted to check if System.Speech was better.
I added the reference, but the Build gives this error and I can't fix it :
Cannot find type System.MarshalByRefObject in module CommonLanguageRuntimeLibrary.
There isn't really a way to use the .NET API System.Speech.Synthesis in a WinRT app, without creating an app that will wind up failing the WACK tests for submission.
Many of the .NET namespaces haven't been projected into WinRT. In particular, System.Speech.* since there's already Windows.Media.SpeechSynthesis and Windows.Media.SpeechRecognition, which were brought over from the windows phone API namespaces instead, and should be functionally complete for the majority of purposes.
Only old .NET APIs that are part of the .NETCore profile have been projected to WinRT.
I need to acquire images from a scanner in my WPF application. I've used the open source TwainDotNet Twain32 wrapper, however, there are some Windows 8.1 devices that throw an AccessViolationException. I would like to use the latest Microsoft supported WIA wrappers in the Windows.Devices.Scanners namespace rather than buy a product to enable scanning on Windows 8.1+ machines.
I've successfully been able to use some of the Windows.Devices.* types for video recording in a WPF app via the following instructions: How to use specific WinRT API from Desktop apps: capturing a photo using your webcam into a WPF app
When you look at the documentation for Windows.Devices.Scanners ImageScanner class, You can see that the minimum supported client is Windows 8.1 [Windows Store apps, desktop apps]. Since it is available to both Windows Store Apps and Desktop apps, this means that you should be able to use this namespace and the associated classes from within WPF. The metadata is listed as Windows.winmd which I believe is already referenced in the project (A reference to Windows) as outlined in the tutorial above.
My question: How can I use the Windows.Devices.Scanners types in a WPF application running on Windows 8.x+ ?
Thanks in advance to all replies
The documentation states that the minimum supported client is Windows 8.1. The tutorial that you used told you to edit the CSPROJ file to add the following code:
<TargetPlatformVersion>8.0</TargetPlatformVersion>
Change this to 8.1 in order to reference 8.1 only types:
<TargetPlatformVersion>8.1</TargetPlatformVersion>
I have MyDotNet4.dll that user installs as application on machine. In my case this is components that will take care of interfacing with TWAIN scanner.
I also have my Silverlight application with elevated permissions (SL4 OOB or SL5 in/out of browser)
I want to somehow invoke methods of MyDotNet4.dll using Silverlight code. Is that possible? How? Any pointers or sample code?
My idea is to have Silverlight app and if user needs scanning - I will let him download and install real windows app and than I would like to somehow talk to this app from Silverlight.
It may not work, but have a look at this blog, http://netfxharmonics.com/2008/12/Reusing-NET-Assemblies-in-Silverlight, see The Assembly-Level Technique section if (as your question suggests) you do not have the source code for the dll in question. I have faint recollection that I used that method as a test a long while back, but since I had the source I ended up going with the file level approach to share common code between a dll referenced by my Silverlight project and my console app project
Silverlight does have local messaging but that works only between two silverlight apps. See the following for LocalMessaging
Msdn page.
Silverlight OOB and mutiple windows - LocalMessaging
From this similar SO post: Communicating with a Silverlight 4 LocalMessageReceiver from a Desktop Application and this other thread here on the silverlight forums seems you're out of luck and you will have to implement your own communication scheme.
I'm assuming your SL app needs to invoke the scanning app and get the image. You could run your scanning app like this and then have the app drop the picture in a know directory which your SL app can then pick.