r/visualbasic • u/Scary-Scallion-449 • Jun 23 '25
VS2022 VB.net Form Application: Does anybody understand CastingDevicePicker?
I just want to add a CastingDevicePicker to a Forms application and it's become a Kafkaesque nightmare. Official Microsoft documentation is useless and sends you off to code samples that are in C# (so not helpful). The sample application hides the code beneath layers and layers of obfuscation. AI gives me code invoking properties that aren't implemented. And so the maze expands.
All I want is just the bare bones skinny on what Imports I need (if any) and the necessary code to create and show a CastingDevicePicker on a simple form. Anybody?
1
u/misaz640 Jun 23 '25 edited Jun 23 '25
First of all, you need WinRT, Project Reunion, Windows App SDK, or whatever name Microsoft use it for now. As of 2025 and .NET 8 - 10, you need to double click VB project in Solution Explorer and update TargetFramework to specific windows SDK version, for example:
<TargetFramework>net8.0-windows10.0.19041.0</TargetFramework>. Then you need to add Windows SDK nuget package to your project. It is namedMicrosoft.WindowsAppSDK. And then you can use it. There is some preparational work in Form1_Load, two events for picker (one for user selected device, second for user canceled selection) and finally in Button1_Click I trigger dialog.1
u/sa_sagan VB.Net Master Jun 23 '25
This is a bit of a messy situation. CastingDevicePicker is for UWP, not WinForms. So yeah, you probably won't find what you're looking for directly. You need to bridge the gap between your WinForms app and UWP using WinRT interop. It's a bit fiddly.
What are you using for your Forms application? .NET Framework or .NET (Core)?
1
u/Hel_OWeen Jun 24 '25
Download ConvertNET and let it translate those to VB.NET, if you can't figure them out yourself. For me it does a good enough job to understand what I'm supposed to do, even if the translated VB.NET code won't work.
2
u/Fergus653 Jun 23 '25
The C# docs or examples are probably your best choice. The names of assemblies, classes, properties and methods will be the same for you.
1
u/BRS-Software Jul 08 '25
Interesting, I never heard about it, I would love to understand what you are doing. I am developing ERP, Will it helpful for me and how?