WPF-UWP Bridge and ShareTarget

Heiko 1,211 Reputation points
2021-08-10T15:09:15.72+00:00
  • I have 2 projects in my solution: one WPF project and one Windows Application Packaging Project. (VS 2017)
  • I have added the Nuget package Microsoft.Windows.SDK.Contracts to the WPF project.
  • I have migrated packages.config to PackageReference.
  • I can compile and run both projects without errors.
  • In the package project, I added a share target with a file type in the package manifest under Declarations, but did not specify a data format.

If my app is now selected as a share target on a file in Explorer, my app is started. But before a big empty window opens with my app icon in the middle. The empty window stays open, you have to close it explicitly.

In the WPF app, I now have the Windows namespace and all namespaces below available.

How do I access the file shared by Explorer in the WPF app?

What do I have to do so that the empty window with the app icon is not visible?

Universal Windows Platform (UWP)
Windows Presentation Foundation
Windows Presentation Foundation
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
2,670 questions
{count} votes

Accepted answer
  1. Roy Li - MSFT 31,766 Reputation points Microsoft Vendor
    2021-08-11T07:13:12.137+00:00

    Hello,

    Welcome to Microsoft Q&A!

    How do I access the file shared by Explorer in the WPF app?

    Well, you could not directly use the WPF app as the share target app. You need to create a UWP app as the share target app and then packaged the UWP app with your WPF app together in the Windows Application Packaging Project. When there is a file to be shared, the UWP app will be the share target, it receives the data and pass the data to your WPF app. Then you could do your logic in your WPF app.

    For more information please check this blog: Extend your desktop application with Windows 10 features using the new Visual Studio Application Packaging Project.

    Thank you.


    If the response is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Heiko 1,211 Reputation points
    2021-08-14T12:24:49.157+00:00

    Thanks for the information.

    I created a blank UWP app and added it to the Packaging project.

    In the UWP project I added a share target under Declarations. As a result, in Explorer for a file type, I am now offered the UWP app as a Share Target.

    Then I created a new app in the partner center. Then, in VS, I associated the Packaging project with the new Store app.

    After that, I associated the UWP app to the same store app as well. After that, I rebuilt everything.

    The result now is that I no longer get the UWP app offered as a Share Target in Explorer, even though the entries for the Share Target are still present in the Package Manifest. I have tried removing these, uninstalling the app, rebooting the PC, re-adding the Share Target, rebuilding the app and running it. But I continue to not get the UWP app offered as a Share Target.

    What am I doing wrong?