简体   繁体   English

如果插入了SmartCard,则发生WPF捕获事件

[英]WPF Catch event if SmartCard is inserted

If I insert a Card in my SmartCard reader on my device. 如果我在设备的SmartCard读卡器中插入卡。 I want to trigger an event in my WPF project. 我想在我的WPF项目中触发一个事件。 Any idea's to achieve that? 有什么想法可以实现吗?

This question was a while ago but I can confirm it is possible. 这个问题是前一段时间,但我可以确认是可能的。 You can reference UWP assemblies. 您可以引用UWP程序集。 Calling Windows 10 APIs From a Desktop Application details how to add the references. 从桌面应用程序调用Windows 10 API详细介绍了如何添加引用。

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. 在引用管理器的左侧,选择“浏览”并找到以下文件: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”. 在引用管理器的左侧,转到“浏览”,然后找到目录“ C:Program Files(x86)Reference AssembliesMicrosoftFramework.NETCorev4.5”。 Add System.Runtime.WindowsRuntime.dll to your project. 将System.Runtime.WindowsRuntime.dll添加到您的项目。

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);
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM