komodosp
komodosp

Reputation: 3656

Access a UWP class from WPF / .Net Framework project

I have a WPF application created with .Net Framework, however I need to use it to enable / disable the Windows 10 hotspot.

After much searching around, apparently the way to do it is using the NetworkOperatorTetheringManager class.

However, I can't use the Windows.Networking.NetworkOperators or add a reference, presumably because it's part of the UWP SDK and not the standard .NET framework. As I understand it, it would have to be built as a UWP application from the beginning.

Is there any way to do access this functionality?

(I've also come across WlanHostedNetworkStartUsing() but this appears to be for the now deprecated netsh hostednetwork rather than the Mobile Hotspot)

Upvotes: 0

Views: 853

Answers (2)

komodosp
komodosp

Reputation: 3656

So what worked for me (as advised on another forum at Microsoft

  1. Install Windows 10 SDK

  2. Add references to

C:\Program Files (x86)\Windows Kits\10\UnionMetadata[version]\Windows.winmd

and

C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETCore\v4.5\System.Runtime.WindowsRuntime.dll`

Then I could do...

using Windows.Networking.Connectivity;
using Windows.Networking.NetworkOperators;

Upvotes: 0

Roy Li - MSFT
Roy Li - MSFT

Reputation: 8681

If you want use UWP API from desktop application that uses .net Framework application or .NET Core 3.x, you just need to install the Microsoft.Windows.SDK.Contracts NuGet package. Then you could use the Windows Runtime API after adding the correct namespace.

More information and detailed explanation here: Call Windows Runtime APIs in desktop apps.

Upvotes: 2

Related Questions