如果插入智能卡,WPF 捕获事件
WPF Catch event if SmartCard is inserted
如果我在设备上的智能卡 reader 中插入一张卡。我想在我的 WPF 项目中触发一个事件。有什么想法可以实现吗?
这个问题很久以前就有了,但我可以确认这是可能的。您可以引用 UWP 程序集。 Calling Windows 10 APIs From a Desktop Application 详细说明如何添加引用。
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.
从那里我按照这个例子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);
}
}
如果我在设备上的智能卡 reader 中插入一张卡。我想在我的 WPF 项目中触发一个事件。有什么想法可以实现吗?
这个问题很久以前就有了,但我可以确认这是可能的。您可以引用 UWP 程序集。 Calling Windows 10 APIs From a Desktop Application 详细说明如何添加引用。
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.
从那里我按照这个例子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);
}
}