If I insert a Card in my SmartCard reader on my device. I want to trigger an event in my WPF project. Any idea's to achieve that?
-
4This doesn't really have anything to do with WPF. See this question and its answer: [Smart Card Reader Plugin (Card Inserted) Event](http://stackoverflow.com/questions/40786160/smart-card-reader-plugin-card-inserted-event) – Kilazur Feb 13 '17 at 14:56
-
This solution cannot be implemented in WPF... – Arne Van De Vyver Feb 15 '17 at 07:38
-
Why is that? What prevents you from creating the class in WPF? – Kilazur Feb 15 '17 at 17:52
-
My mistake, it seems UWP only, which I find hard to believe – Kilazur Feb 15 '17 at 17:57
1 Answers
This question was a while ago but I can confirm it is possible. You can reference UWP assemblies. Calling Windows 10 APIs From a Desktop Application details how to add the references.
Right click on References. Select “Add Reference…” from the context menu. On the left of the Reference Manager, choose Browse and find the following file: C:Program Files (x86)Windows Kits10UnionMetadatawinmd. Add it to your project as a reference. Note: You will need to change the filter to “All Files”.
Right click on References. Select “Add Reference…” from the context menu. On the left of the Reference Manager, go to Browse and find the directory “C:Program Files (x86)Reference AssembliesMicrosoftFramework.NETCorev4.5”. Add System.Runtime.WindowsRuntime.dll to your project.
From there I follow this example Getting all Cards simply cutting and pasting the major part. Once you have reader you can then add the Card Added Event
string selector = SmartCardReader.GetDeviceSelector();
DeviceInformationCollection devices = await DeviceInformation.FindAllAsync(selector);
foreach (DeviceInformation device in devices)
{
SmartCardReader reader = await SmartCardReader.FromIdAsync(device.Id);
// For each reader, we want to find all the cards associated
// with it. Then we will create a SmartCardListItem for
// each (reader, card) pair.
IReadOnlyList<SmartCard> cards = await reader.FindAllCardsAsync();
foreach (SmartCard card in cards)
{
SmartCardProvisioning provisioning = await SmartCardProvisioning.FromSmartCardAsync(card);
SmartCardListItem item = new SmartCardListItem()
{
ReaderName = card.Reader.Name,
CardName = await provisioning.GetNameAsync()
};
cardItems.Add(item);
}
}