├── PreviewPaneExtensionSample ├── PreviewPaneExtensionSample │ ├── Public │ │ └── FileExtensions.json │ ├── Assets │ │ ├── FilesHome.png │ │ ├── StoreLogo.png │ │ ├── SplashScreen.scale-200.png │ │ ├── LockScreenLogo.scale-200.png │ │ ├── Square44x44Logo.scale-200.png │ │ ├── Wide310x150Logo.scale-200.png │ │ ├── Square150x150Logo.scale-200.png │ │ └── Square44x44Logo.targetsize-24_altform-unplated.png │ ├── App.xaml │ ├── MainPage.xaml │ ├── MainPage.xaml.cs │ ├── Properties │ │ ├── AssemblyInfo.cs │ │ └── Default.rd.xml │ ├── Package.appxmanifest │ ├── App.xaml.cs │ └── PreviewPaneExtensionSample.csproj ├── FilePreviewService │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── Preview.cs │ └── FilePreviewService.csproj └── PreviewPaneExtensionSample.sln ├── screenshots └── Output.png ├── LICENSE ├── README.md └── .gitignore /PreviewPaneExtensionSample/PreviewPaneExtensionSample/Public/FileExtensions.json: -------------------------------------------------------------------------------- 1 | [ 2 | ".files" 3 | ] -------------------------------------------------------------------------------- /screenshots/Output.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/files-community/Preview-pane-sample-extension/HEAD/screenshots/Output.png -------------------------------------------------------------------------------- /PreviewPaneExtensionSample/PreviewPaneExtensionSample/Assets/FilesHome.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/files-community/Preview-pane-sample-extension/HEAD/PreviewPaneExtensionSample/PreviewPaneExtensionSample/Assets/FilesHome.png -------------------------------------------------------------------------------- /PreviewPaneExtensionSample/PreviewPaneExtensionSample/Assets/StoreLogo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/files-community/Preview-pane-sample-extension/HEAD/PreviewPaneExtensionSample/PreviewPaneExtensionSample/Assets/StoreLogo.png -------------------------------------------------------------------------------- /PreviewPaneExtensionSample/PreviewPaneExtensionSample/Assets/SplashScreen.scale-200.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/files-community/Preview-pane-sample-extension/HEAD/PreviewPaneExtensionSample/PreviewPaneExtensionSample/Assets/SplashScreen.scale-200.png -------------------------------------------------------------------------------- /PreviewPaneExtensionSample/PreviewPaneExtensionSample/Assets/LockScreenLogo.scale-200.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/files-community/Preview-pane-sample-extension/HEAD/PreviewPaneExtensionSample/PreviewPaneExtensionSample/Assets/LockScreenLogo.scale-200.png -------------------------------------------------------------------------------- /PreviewPaneExtensionSample/PreviewPaneExtensionSample/Assets/Square44x44Logo.scale-200.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/files-community/Preview-pane-sample-extension/HEAD/PreviewPaneExtensionSample/PreviewPaneExtensionSample/Assets/Square44x44Logo.scale-200.png -------------------------------------------------------------------------------- /PreviewPaneExtensionSample/PreviewPaneExtensionSample/Assets/Wide310x150Logo.scale-200.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/files-community/Preview-pane-sample-extension/HEAD/PreviewPaneExtensionSample/PreviewPaneExtensionSample/Assets/Wide310x150Logo.scale-200.png -------------------------------------------------------------------------------- /PreviewPaneExtensionSample/PreviewPaneExtensionSample/Assets/Square150x150Logo.scale-200.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/files-community/Preview-pane-sample-extension/HEAD/PreviewPaneExtensionSample/PreviewPaneExtensionSample/Assets/Square150x150Logo.scale-200.png -------------------------------------------------------------------------------- /PreviewPaneExtensionSample/PreviewPaneExtensionSample/Assets/Square44x44Logo.targetsize-24_altform-unplated.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/files-community/Preview-pane-sample-extension/HEAD/PreviewPaneExtensionSample/PreviewPaneExtensionSample/Assets/Square44x44Logo.targetsize-24_altform-unplated.png -------------------------------------------------------------------------------- /PreviewPaneExtensionSample/PreviewPaneExtensionSample/App.xaml: -------------------------------------------------------------------------------- 1 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /PreviewPaneExtensionSample/PreviewPaneExtensionSample/MainPage.xaml: -------------------------------------------------------------------------------- 1 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /PreviewPaneExtensionSample/PreviewPaneExtensionSample/MainPage.xaml.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Runtime.InteropServices.WindowsRuntime; 6 | using Windows.Foundation; 7 | using Windows.Foundation.Collections; 8 | using Windows.UI.Xaml; 9 | using Windows.UI.Xaml.Controls; 10 | using Windows.UI.Xaml.Controls.Primitives; 11 | using Windows.UI.Xaml.Data; 12 | using Windows.UI.Xaml.Input; 13 | using Windows.UI.Xaml.Media; 14 | using Windows.UI.Xaml.Navigation; 15 | 16 | // The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x409 17 | 18 | namespace PreviewPaneExtensionSample 19 | { 20 | /// 21 | /// An empty page that can be used on its own or navigated to within a Frame. 22 | /// 23 | public sealed partial class MainPage : Page 24 | { 25 | public MainPage() 26 | { 27 | this.InitializeComponent(); 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Files Community 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /PreviewPaneExtensionSample/FilePreviewService/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("FilePreviewService")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("FilePreviewService")] 13 | [assembly: AssemblyCopyright("Copyright © 2020")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Version information for an assembly consists of the following four values: 18 | // 19 | // Major Version 20 | // Minor Version 21 | // Build Number 22 | // Revision 23 | // 24 | // You can specify all the values or you can default the Build and Revision Numbers 25 | // by using the '*' as shown below: 26 | // [assembly: AssemblyVersion("1.0.*")] 27 | [assembly: AssemblyVersion("1.0.0.0")] 28 | [assembly: AssemblyFileVersion("1.0.0.0")] 29 | [assembly: ComVisible(false)] -------------------------------------------------------------------------------- /PreviewPaneExtensionSample/PreviewPaneExtensionSample/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("PreviewPaneExtensionSample")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("PreviewPaneExtensionSample")] 13 | [assembly: AssemblyCopyright("Copyright © 2021")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Version information for an assembly consists of the following four values: 18 | // 19 | // Major Version 20 | // Minor Version 21 | // Build Number 22 | // Revision 23 | // 24 | // You can specify all the values or you can default the Build and Revision Numbers 25 | // by using the '*' as shown below: 26 | // [assembly: AssemblyVersion("1.0.*")] 27 | [assembly: AssemblyVersion("1.0.0.0")] 28 | [assembly: AssemblyFileVersion("1.0.0.0")] 29 | [assembly: ComVisible(false)] -------------------------------------------------------------------------------- /PreviewPaneExtensionSample/PreviewPaneExtensionSample/Properties/Default.rd.xml: -------------------------------------------------------------------------------- 1 | 17 | 18 | 19 | 20 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /PreviewPaneExtensionSample/PreviewPaneExtensionSample/Package.appxmanifest: -------------------------------------------------------------------------------- 1 | 2 | 3 | 10 | 11 | 15 | 16 | 17 | 18 | 19 | PreviewPaneExtensionSample 20 | winis 21 | Assets\StoreLogo.png 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 36 | 42 | 43 | 44 | 45 | 46 | 47 | 52 | 53 | com.markdownpreview.controlservice 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | -------------------------------------------------------------------------------- /PreviewPaneExtensionSample/PreviewPaneExtensionSample/App.xaml.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Runtime.InteropServices.WindowsRuntime; 6 | using Windows.ApplicationModel; 7 | using Windows.ApplicationModel.Activation; 8 | using Windows.Foundation; 9 | using Windows.Foundation.Collections; 10 | using Windows.UI.Xaml; 11 | using Windows.UI.Xaml.Controls; 12 | using Windows.UI.Xaml.Controls.Primitives; 13 | using Windows.UI.Xaml.Data; 14 | using Windows.UI.Xaml.Input; 15 | using Windows.UI.Xaml.Media; 16 | using Windows.UI.Xaml.Navigation; 17 | 18 | namespace PreviewPaneExtensionSample 19 | { 20 | /// 21 | /// Provides application-specific behavior to supplement the default Application class. 22 | /// 23 | sealed partial class App : Application 24 | { 25 | /// 26 | /// Initializes the singleton application object. This is the first line of authored code 27 | /// executed, and as such is the logical equivalent of main() or WinMain(). 28 | /// 29 | public App() 30 | { 31 | this.InitializeComponent(); 32 | this.Suspending += OnSuspending; 33 | } 34 | 35 | /// 36 | /// Invoked when the application is launched normally by the end user. Other entry points 37 | /// will be used such as when the application is launched to open a specific file. 38 | /// 39 | /// Details about the launch request and process. 40 | protected override void OnLaunched(LaunchActivatedEventArgs e) 41 | { 42 | Frame rootFrame = Window.Current.Content as Frame; 43 | 44 | // Do not repeat app initialization when the Window already has content, 45 | // just ensure that the window is active 46 | if (rootFrame == null) 47 | { 48 | // Create a Frame to act as the navigation context and navigate to the first page 49 | rootFrame = new Frame(); 50 | 51 | rootFrame.NavigationFailed += OnNavigationFailed; 52 | 53 | if (e.PreviousExecutionState == ApplicationExecutionState.Terminated) 54 | { 55 | //TODO: Load state from previously suspended application 56 | } 57 | 58 | // Place the frame in the current Window 59 | Window.Current.Content = rootFrame; 60 | } 61 | 62 | if (e.PrelaunchActivated == false) 63 | { 64 | if (rootFrame.Content == null) 65 | { 66 | // When the navigation stack isn't restored navigate to the first page, 67 | // configuring the new page by passing required information as a navigation 68 | // parameter 69 | rootFrame.Navigate(typeof(MainPage), e.Arguments); 70 | } 71 | // Ensure the current window is active 72 | Window.Current.Activate(); 73 | } 74 | } 75 | 76 | /// 77 | /// Invoked when Navigation to a certain page fails 78 | /// 79 | /// The Frame which failed navigation 80 | /// Details about the navigation failure 81 | void OnNavigationFailed(object sender, NavigationFailedEventArgs e) 82 | { 83 | throw new Exception("Failed to load Page " + e.SourcePageType.FullName); 84 | } 85 | 86 | /// 87 | /// Invoked when application execution is being suspended. Application state is saved 88 | /// without knowing whether the application will be terminated or resumed with the contents 89 | /// of memory still intact. 90 | /// 91 | /// The source of the suspend request. 92 | /// Details about the suspend request. 93 | private void OnSuspending(object sender, SuspendingEventArgs e) 94 | { 95 | var deferral = e.SuspendingOperation.GetDeferral(); 96 | //TODO: Save application state and stop any background activity 97 | deferral.Complete(); 98 | } 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Preview Pane Sample Extension 2 | This is an example of an app that extends Files to provide a file preview for the file type ".files". 3 | 4 | Output: 5 | ![](screenshots/output.png) 6 | 7 | 8 | ## Making your own preview serivce 9 | 10 | Support for previews is provided by the service "com.markdownpreview.controlservice". Files locates the name of this service by reading the service property registered in the app manifest. You're manifest should look something like this: 11 | ```xml 12 | 13 | 14 | 19 | 20 | com.markdownpreview.controlservice 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | ``` 29 | Files also looks at the FileExtensions.json file to get a list of file extensions that the preview service is registered for. If the selected file has an extension listed within this file, then Files will call the extension's service. 30 | 31 | ### Accessing a file 32 | As part of the request to the preview service, Files sends a token which can be used to redeem a StorageFile without the extensions needing full filesystem access. 33 | The storage file can redeemed like this: 34 | ```cs 35 | var message = args.Request.Message; 36 | StorageFile file = await SharedStorageAccessManager.RedeemTokenForFileAsync(message["token"] as string); 37 | ``` 38 | 39 | ### Preview controls 40 | Previews are sent as a string containing xaml that is then loaded into the preview pane using the ```XamlReader```. You can define this string as the "preview" parameter in the response. This does have it's limitations, as only controls that are already avaliable to Files can be used. This means that extensions are limited to standard WinUI controls, and controls from the Windows Community Toolkit. 41 | 42 | This is an example of a string that can be sent back to Files. 43 | ```xml 44 | 45 | 46 | Hello, world! 47 | 48 | 49 | ``` 50 | ### Preview Images 51 | 52 | Since images can't be sent in the response, Files allows images to be loaded as Base64 string that represents the images buffer. See the sample service for an example of this. 53 | This is an 54 | This is an example of how you would encode your image as a base64 string, and add that to the xaml string. 55 | ```cs 56 | var base64string = ""; 57 | var file = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///Assets/FilesHome.png")); 58 | var stream = await file.OpenReadAsync(); 59 | 60 | using (var memoryStream = new MemoryStream()) 61 | { 62 | memoryStream.Capacity = (int)stream.Size; 63 | var ibuffer = memoryStream.GetWindowsRuntimeBuffer(); 64 | ibuffer = await stream.ReadAsync(ibuffer, (uint)stream.Size, InputStreamOptions.None).AsTask().ConfigureAwait(false); 65 | var byteArray = ibuffer.ToArray(); 66 | base64string = Convert.ToBase64String(byteArray); 67 | } 68 | var xaml = $" 69 | 70 | 71 | {base64string} 72 | 73 | 74 | 75 | ``` 76 | 77 | ### Details 78 | 79 | File details are sent as a Json string with the parameter name "details", which is deserialized by Files, and then added to the details list in the preview pane. 80 | The two Properties you will need for this are "LocalizedName" and "Value" of types ```string``` and ```object```, respectively. 81 | This is an example of valid Json data that can be used by Files. 82 | ```json 83 | [ 84 | { 85 | "LocalizedName": "Hello", 86 | "Value": "World!", 87 | } 88 | ] 89 | ``` 90 | 91 | ### Specifying file types 92 | 93 | Preview extensions can specify the types of files they support by adding them to a json list in a file named ```FileExtensions.json``` in the extension's public folder. 94 | -------------------------------------------------------------------------------- /PreviewPaneExtensionSample/PreviewPaneExtensionSample.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.30804.86 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PreviewPaneExtensionSample", "PreviewPaneExtensionSample\PreviewPaneExtensionSample.csproj", "{52494317-8F3C-4ED1-B0C9-EA3979654352}" 7 | EndProject 8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FilePreviewService", "FilePreviewService\FilePreviewService.csproj", "{E12C85B3-2B31-4783-9BF0-D251A8599750}" 9 | EndProject 10 | Global 11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 12 | Debug|Any CPU = Debug|Any CPU 13 | Debug|ARM = Debug|ARM 14 | Debug|ARM64 = Debug|ARM64 15 | Debug|x64 = Debug|x64 16 | Debug|x86 = Debug|x86 17 | Release|Any CPU = Release|Any CPU 18 | Release|ARM = Release|ARM 19 | Release|ARM64 = Release|ARM64 20 | Release|x64 = Release|x64 21 | Release|x86 = Release|x86 22 | EndGlobalSection 23 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 24 | {52494317-8F3C-4ED1-B0C9-EA3979654352}.Debug|Any CPU.ActiveCfg = Debug|x86 25 | {52494317-8F3C-4ED1-B0C9-EA3979654352}.Debug|ARM.ActiveCfg = Debug|ARM 26 | {52494317-8F3C-4ED1-B0C9-EA3979654352}.Debug|ARM.Build.0 = Debug|ARM 27 | {52494317-8F3C-4ED1-B0C9-EA3979654352}.Debug|ARM.Deploy.0 = Debug|ARM 28 | {52494317-8F3C-4ED1-B0C9-EA3979654352}.Debug|ARM64.ActiveCfg = Debug|ARM64 29 | {52494317-8F3C-4ED1-B0C9-EA3979654352}.Debug|ARM64.Build.0 = Debug|ARM64 30 | {52494317-8F3C-4ED1-B0C9-EA3979654352}.Debug|ARM64.Deploy.0 = Debug|ARM64 31 | {52494317-8F3C-4ED1-B0C9-EA3979654352}.Debug|x64.ActiveCfg = Debug|x64 32 | {52494317-8F3C-4ED1-B0C9-EA3979654352}.Debug|x64.Build.0 = Debug|x64 33 | {52494317-8F3C-4ED1-B0C9-EA3979654352}.Debug|x64.Deploy.0 = Debug|x64 34 | {52494317-8F3C-4ED1-B0C9-EA3979654352}.Debug|x86.ActiveCfg = Debug|x86 35 | {52494317-8F3C-4ED1-B0C9-EA3979654352}.Debug|x86.Build.0 = Debug|x86 36 | {52494317-8F3C-4ED1-B0C9-EA3979654352}.Debug|x86.Deploy.0 = Debug|x86 37 | {52494317-8F3C-4ED1-B0C9-EA3979654352}.Release|Any CPU.ActiveCfg = Release|x86 38 | {52494317-8F3C-4ED1-B0C9-EA3979654352}.Release|ARM.ActiveCfg = Release|ARM 39 | {52494317-8F3C-4ED1-B0C9-EA3979654352}.Release|ARM.Build.0 = Release|ARM 40 | {52494317-8F3C-4ED1-B0C9-EA3979654352}.Release|ARM.Deploy.0 = Release|ARM 41 | {52494317-8F3C-4ED1-B0C9-EA3979654352}.Release|ARM64.ActiveCfg = Release|ARM64 42 | {52494317-8F3C-4ED1-B0C9-EA3979654352}.Release|ARM64.Build.0 = Release|ARM64 43 | {52494317-8F3C-4ED1-B0C9-EA3979654352}.Release|ARM64.Deploy.0 = Release|ARM64 44 | {52494317-8F3C-4ED1-B0C9-EA3979654352}.Release|x64.ActiveCfg = Release|x64 45 | {52494317-8F3C-4ED1-B0C9-EA3979654352}.Release|x64.Build.0 = Release|x64 46 | {52494317-8F3C-4ED1-B0C9-EA3979654352}.Release|x64.Deploy.0 = Release|x64 47 | {52494317-8F3C-4ED1-B0C9-EA3979654352}.Release|x86.ActiveCfg = Release|x86 48 | {52494317-8F3C-4ED1-B0C9-EA3979654352}.Release|x86.Build.0 = Release|x86 49 | {52494317-8F3C-4ED1-B0C9-EA3979654352}.Release|x86.Deploy.0 = Release|x86 50 | {E12C85B3-2B31-4783-9BF0-D251A8599750}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 51 | {E12C85B3-2B31-4783-9BF0-D251A8599750}.Debug|Any CPU.Build.0 = Debug|Any CPU 52 | {E12C85B3-2B31-4783-9BF0-D251A8599750}.Debug|ARM.ActiveCfg = Debug|ARM 53 | {E12C85B3-2B31-4783-9BF0-D251A8599750}.Debug|ARM.Build.0 = Debug|ARM 54 | {E12C85B3-2B31-4783-9BF0-D251A8599750}.Debug|ARM64.ActiveCfg = Debug|ARM64 55 | {E12C85B3-2B31-4783-9BF0-D251A8599750}.Debug|ARM64.Build.0 = Debug|ARM64 56 | {E12C85B3-2B31-4783-9BF0-D251A8599750}.Debug|x64.ActiveCfg = Debug|x64 57 | {E12C85B3-2B31-4783-9BF0-D251A8599750}.Debug|x64.Build.0 = Debug|x64 58 | {E12C85B3-2B31-4783-9BF0-D251A8599750}.Debug|x86.ActiveCfg = Debug|x86 59 | {E12C85B3-2B31-4783-9BF0-D251A8599750}.Debug|x86.Build.0 = Debug|x86 60 | {E12C85B3-2B31-4783-9BF0-D251A8599750}.Release|Any CPU.ActiveCfg = Release|Any CPU 61 | {E12C85B3-2B31-4783-9BF0-D251A8599750}.Release|Any CPU.Build.0 = Release|Any CPU 62 | {E12C85B3-2B31-4783-9BF0-D251A8599750}.Release|ARM.ActiveCfg = Release|ARM 63 | {E12C85B3-2B31-4783-9BF0-D251A8599750}.Release|ARM.Build.0 = Release|ARM 64 | {E12C85B3-2B31-4783-9BF0-D251A8599750}.Release|ARM64.ActiveCfg = Release|ARM64 65 | {E12C85B3-2B31-4783-9BF0-D251A8599750}.Release|ARM64.Build.0 = Release|ARM64 66 | {E12C85B3-2B31-4783-9BF0-D251A8599750}.Release|x64.ActiveCfg = Release|x64 67 | {E12C85B3-2B31-4783-9BF0-D251A8599750}.Release|x64.Build.0 = Release|x64 68 | {E12C85B3-2B31-4783-9BF0-D251A8599750}.Release|x86.ActiveCfg = Release|x86 69 | {E12C85B3-2B31-4783-9BF0-D251A8599750}.Release|x86.Build.0 = Release|x86 70 | EndGlobalSection 71 | GlobalSection(SolutionProperties) = preSolution 72 | HideSolutionNode = FALSE 73 | EndGlobalSection 74 | GlobalSection(ExtensibilityGlobals) = postSolution 75 | SolutionGuid = {CD2DF5D3-7F60-4D3C-A4ED-CDAFD32585EE} 76 | EndGlobalSection 77 | EndGlobal 78 | -------------------------------------------------------------------------------- /PreviewPaneExtensionSample/FilePreviewService/Preview.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Diagnostics; 5 | using System.IO; 6 | using System.Linq; 7 | using System.Runtime.InteropServices.WindowsRuntime; 8 | using System.Text; 9 | using System.Threading.Tasks; 10 | using System.Web; 11 | using System.Xml; 12 | using Windows.ApplicationModel.AppService; 13 | using Windows.ApplicationModel.Background; 14 | using Windows.ApplicationModel.DataTransfer; 15 | using Windows.Foundation.Collections; 16 | using Windows.Storage; 17 | using Windows.Storage.Streams; 18 | using Windows.UI.Xaml.Controls; 19 | using Windows.UI.Xaml.Media; 20 | using Windows.UI.Xaml.Media.Imaging; 21 | 22 | namespace FilePreviewService 23 | { 24 | public sealed class Preview : IBackgroundTask 25 | { 26 | private BackgroundTaskDeferral backgroundTaskDeferral; 27 | private AppServiceConnection appServiceconnection; 28 | private String[] inventoryItems = new string[] { "Robot vacuum", "Chair" }; 29 | private double[] inventoryPrices = new double[] { 129.99, 88.99 }; 30 | 31 | public void Run(IBackgroundTaskInstance taskInstance) 32 | { 33 | // Get a deferral so that the service isn't terminated. 34 | this.backgroundTaskDeferral = taskInstance.GetDeferral(); 35 | 36 | // Associate a cancellation handler with the background task. 37 | taskInstance.Canceled += OnTaskCanceled; 38 | 39 | // Retrieve the app service connection and set up a listener for incoming app service requests. 40 | var details = taskInstance.TriggerDetails as AppServiceTriggerDetails; 41 | appServiceconnection = details.AppServiceConnection; 42 | appServiceconnection.RequestReceived += OnRequestReceived; 43 | } 44 | 45 | private async void OnRequestReceived(AppServiceConnection sender, AppServiceRequestReceivedEventArgs args) 46 | { 47 | // This function is called when the app service receives a request. 48 | // Get a deferral because we use an awaitable API below (SendResponseAsync()) to respond to the message 49 | // and we don't want this call to get cancelled while we are waiting. 50 | AppServiceDeferral messageDeferral = args.GetDeferral(); 51 | var message = args.Request.Message; 52 | var returnMessage = new ValueSet(); 53 | 54 | // Files sends a shared file access token that can be used to redeem a storage file 55 | 56 | var file = await SharedStorageAccessManager.RedeemTokenForFileAsync(message["token"] as string); 57 | 58 | //var buffer = bytearray.AsBuffer(); 59 | var text = await FileIO.ReadTextAsync(file); 60 | 61 | var result = await GetEncodedImage(); 62 | 63 | // in order to be usable by files, images must be encoded into a base64 string, and added as the EncodedImage property 64 | string xaml = $" { System.Security.SecurityElement.Escape(result) }"; 65 | returnMessage.Add("preview", xaml); 66 | 67 | var props = new List() { 68 | new FileProperty() {LocalizedName = "Hello", Value = "World!!!"} 69 | }; 70 | 71 | // This code loads in a sample details for Files to display in the preview pane 72 | var json = JsonConvert.SerializeObject(props); 73 | returnMessage.Add("details", json); 74 | await args.Request.SendResponseAsync(returnMessage); 75 | 76 | messageDeferral.Complete(); 77 | } 78 | 79 | 80 | private async Task GetEncodedImage() 81 | { 82 | var file = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///Assets/FilesHome.png")); 83 | var stream = await file.OpenReadAsync(); 84 | 85 | using (var memoryStream = new MemoryStream()) 86 | { 87 | memoryStream.Capacity = (int)stream.Size; 88 | var ibuffer = memoryStream.GetWindowsRuntimeBuffer(); 89 | ibuffer = await stream.ReadAsync(ibuffer, (uint)stream.Size, InputStreamOptions.None).AsTask().ConfigureAwait(false); 90 | var byteArray = ibuffer.ToArray(); 91 | return Convert.ToBase64String(byteArray); 92 | } 93 | } 94 | 95 | private void OnTaskCanceled(IBackgroundTaskInstance sender, BackgroundTaskCancellationReason reason) 96 | { 97 | if (this.backgroundTaskDeferral != null) 98 | { 99 | // Complete the service deferral. 100 | this.backgroundTaskDeferral.Complete(); 101 | } 102 | } 103 | 104 | internal struct FileProperty 105 | { 106 | public string LocalizedName { get; set; } 107 | public object Value { get; set; } 108 | } 109 | } 110 | } 111 | -------------------------------------------------------------------------------- /PreviewPaneExtensionSample/FilePreviewService/FilePreviewService.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {E12C85B3-2B31-4783-9BF0-D251A8599750} 8 | winmdobj 9 | Properties 10 | FilePreviewService 11 | FilePreviewService 12 | en-US 13 | UAP 14 | 10.0.19041.0 15 | 10.0.17763.0 16 | 14 17 | 512 18 | {A5A43C5B-DE2A-4C0C-9213-0A381AF9435A};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 19 | false 20 | 21 | 22 | AnyCPU 23 | true 24 | full 25 | false 26 | bin\Debug\ 27 | DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP 28 | prompt 29 | 4 30 | 31 | 32 | AnyCPU 33 | pdbonly 34 | true 35 | bin\Release\ 36 | TRACE;NETFX_CORE;WINDOWS_UWP 37 | prompt 38 | 4 39 | 40 | 41 | x86 42 | true 43 | bin\x86\Debug\ 44 | DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP 45 | ;2008 46 | full 47 | false 48 | prompt 49 | 50 | 51 | x86 52 | bin\x86\Release\ 53 | TRACE;NETFX_CORE;WINDOWS_UWP 54 | true 55 | ;2008 56 | pdbonly 57 | false 58 | prompt 59 | 60 | 61 | ARM 62 | true 63 | bin\ARM\Debug\ 64 | DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP 65 | ;2008 66 | full 67 | false 68 | prompt 69 | 70 | 71 | ARM 72 | bin\ARM\Release\ 73 | TRACE;NETFX_CORE;WINDOWS_UWP 74 | true 75 | ;2008 76 | pdbonly 77 | false 78 | prompt 79 | 80 | 81 | ARM64 82 | true 83 | bin\ARM64\Debug\ 84 | DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP 85 | ;2008 86 | full 87 | false 88 | prompt 89 | 90 | 91 | ARM64 92 | bin\ARM64\Release\ 93 | TRACE;NETFX_CORE;WINDOWS_UWP 94 | true 95 | ;2008 96 | pdbonly 97 | false 98 | prompt 99 | 100 | 101 | x64 102 | true 103 | bin\x64\Debug\ 104 | DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP 105 | ;2008 106 | full 107 | false 108 | prompt 109 | 110 | 111 | x64 112 | bin\x64\Release\ 113 | TRACE;NETFX_CORE;WINDOWS_UWP 114 | true 115 | ;2008 116 | pdbonly 117 | false 118 | prompt 119 | 120 | 121 | PackageReference 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 6.2.10 130 | 131 | 132 | 12.0.3 133 | 134 | 135 | 136 | 14.0 137 | 138 | 139 | 146 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.rsuser 8 | *.suo 9 | *.user 10 | *.userosscache 11 | *.sln.docstates 12 | 13 | # User-specific files (MonoDevelop/Xamarin Studio) 14 | *.userprefs 15 | 16 | # Mono auto generated files 17 | mono_crash.* 18 | 19 | # Build results 20 | [Dd]ebug/ 21 | [Dd]ebugPublic/ 22 | [Rr]elease/ 23 | [Rr]eleases/ 24 | x64/ 25 | x86/ 26 | [Aa][Rr][Mm]/ 27 | [Aa][Rr][Mm]64/ 28 | bld/ 29 | [Bb]in/ 30 | [Oo]bj/ 31 | [Ll]og/ 32 | [Ll]ogs/ 33 | 34 | # Visual Studio 2015/2017 cache/options directory 35 | .vs/ 36 | # Uncomment if you have tasks that create the project's static files in wwwroot 37 | #wwwroot/ 38 | 39 | # Visual Studio 2017 auto generated files 40 | Generated\ Files/ 41 | 42 | # MSTest test Results 43 | [Tt]est[Rr]esult*/ 44 | [Bb]uild[Ll]og.* 45 | 46 | # NUnit 47 | *.VisualState.xml 48 | TestResult.xml 49 | nunit-*.xml 50 | 51 | # Build Results of an ATL Project 52 | [Dd]ebugPS/ 53 | [Rr]eleasePS/ 54 | dlldata.c 55 | 56 | # Benchmark Results 57 | BenchmarkDotNet.Artifacts/ 58 | 59 | # .NET Core 60 | project.lock.json 61 | project.fragment.lock.json 62 | artifacts/ 63 | 64 | # StyleCop 65 | StyleCopReport.xml 66 | 67 | # Files built by Visual Studio 68 | *_i.c 69 | *_p.c 70 | *_h.h 71 | *.ilk 72 | *.meta 73 | *.obj 74 | *.iobj 75 | *.pch 76 | *.pdb 77 | *.ipdb 78 | *.pgc 79 | *.pgd 80 | *.rsp 81 | *.sbr 82 | *.tlb 83 | *.tli 84 | *.tlh 85 | *.tmp 86 | *.tmp_proj 87 | *_wpftmp.csproj 88 | *.log 89 | *.vspscc 90 | *.vssscc 91 | .builds 92 | *.pidb 93 | *.svclog 94 | *.scc 95 | 96 | # Chutzpah Test files 97 | _Chutzpah* 98 | 99 | # Visual C++ cache files 100 | ipch/ 101 | *.aps 102 | *.ncb 103 | *.opendb 104 | *.opensdf 105 | *.sdf 106 | *.cachefile 107 | *.VC.db 108 | *.VC.VC.opendb 109 | 110 | # Visual Studio profiler 111 | *.psess 112 | *.vsp 113 | *.vspx 114 | *.sap 115 | 116 | # Visual Studio Trace Files 117 | *.e2e 118 | 119 | # TFS 2012 Local Workspace 120 | $tf/ 121 | 122 | # Guidance Automation Toolkit 123 | *.gpState 124 | 125 | # ReSharper is a .NET coding add-in 126 | _ReSharper*/ 127 | *.[Rr]e[Ss]harper 128 | *.DotSettings.user 129 | 130 | # TeamCity is a build add-in 131 | _TeamCity* 132 | 133 | # DotCover is a Code Coverage Tool 134 | *.dotCover 135 | 136 | # AxoCover is a Code Coverage Tool 137 | .axoCover/* 138 | !.axoCover/settings.json 139 | 140 | # Visual Studio code coverage results 141 | *.coverage 142 | *.coveragexml 143 | 144 | # NCrunch 145 | _NCrunch_* 146 | .*crunch*.local.xml 147 | nCrunchTemp_* 148 | 149 | # MightyMoose 150 | *.mm.* 151 | AutoTest.Net/ 152 | 153 | # Web workbench (sass) 154 | .sass-cache/ 155 | 156 | # Installshield output folder 157 | [Ee]xpress/ 158 | 159 | # DocProject is a documentation generator add-in 160 | DocProject/buildhelp/ 161 | DocProject/Help/*.HxT 162 | DocProject/Help/*.HxC 163 | DocProject/Help/*.hhc 164 | DocProject/Help/*.hhk 165 | DocProject/Help/*.hhp 166 | DocProject/Help/Html2 167 | DocProject/Help/html 168 | 169 | # Click-Once directory 170 | publish/ 171 | 172 | # Publish Web Output 173 | *.[Pp]ublish.xml 174 | *.azurePubxml 175 | # Note: Comment the next line if you want to checkin your web deploy settings, 176 | # but database connection strings (with potential passwords) will be unencrypted 177 | *.pubxml 178 | *.publishproj 179 | 180 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 181 | # checkin your Azure Web App publish settings, but sensitive information contained 182 | # in these scripts will be unencrypted 183 | PublishScripts/ 184 | 185 | # NuGet Packages 186 | *.nupkg 187 | # NuGet Symbol Packages 188 | *.snupkg 189 | # The packages folder can be ignored because of Package Restore 190 | **/[Pp]ackages/* 191 | # except build/, which is used as an MSBuild target. 192 | !**/[Pp]ackages/build/ 193 | # Uncomment if necessary however generally it will be regenerated when needed 194 | #!**/[Pp]ackages/repositories.config 195 | # NuGet v3's project.json files produces more ignorable files 196 | *.nuget.props 197 | *.nuget.targets 198 | 199 | # Microsoft Azure Build Output 200 | csx/ 201 | *.build.csdef 202 | 203 | # Microsoft Azure Emulator 204 | ecf/ 205 | rcf/ 206 | 207 | # Windows Store app package directories and files 208 | AppPackages/ 209 | BundleArtifacts/ 210 | Package.StoreAssociation.xml 211 | _pkginfo.txt 212 | *.appx 213 | *.appxbundle 214 | *.appxupload 215 | 216 | # Visual Studio cache files 217 | # files ending in .cache can be ignored 218 | *.[Cc]ache 219 | # but keep track of directories ending in .cache 220 | !?*.[Cc]ache/ 221 | 222 | # Others 223 | ClientBin/ 224 | ~$* 225 | *~ 226 | *.dbmdl 227 | *.dbproj.schemaview 228 | *.jfm 229 | *.pfx 230 | *.publishsettings 231 | orleans.codegen.cs 232 | 233 | # Including strong name files can present a security risk 234 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 235 | #*.snk 236 | 237 | # Since there are multiple workflows, uncomment next line to ignore bower_components 238 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 239 | #bower_components/ 240 | 241 | # RIA/Silverlight projects 242 | Generated_Code/ 243 | 244 | # Backup & report files from converting an old project file 245 | # to a newer Visual Studio version. Backup files are not needed, 246 | # because we have git ;-) 247 | _UpgradeReport_Files/ 248 | Backup*/ 249 | UpgradeLog*.XML 250 | UpgradeLog*.htm 251 | ServiceFabricBackup/ 252 | *.rptproj.bak 253 | 254 | # SQL Server files 255 | *.mdf 256 | *.ldf 257 | *.ndf 258 | 259 | # Business Intelligence projects 260 | *.rdl.data 261 | *.bim.layout 262 | *.bim_*.settings 263 | *.rptproj.rsuser 264 | *- [Bb]ackup.rdl 265 | *- [Bb]ackup ([0-9]).rdl 266 | *- [Bb]ackup ([0-9][0-9]).rdl 267 | 268 | # Microsoft Fakes 269 | FakesAssemblies/ 270 | 271 | # GhostDoc plugin setting file 272 | *.GhostDoc.xml 273 | 274 | # Node.js Tools for Visual Studio 275 | .ntvs_analysis.dat 276 | node_modules/ 277 | 278 | # Visual Studio 6 build log 279 | *.plg 280 | 281 | # Visual Studio 6 workspace options file 282 | *.opt 283 | 284 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 285 | *.vbw 286 | 287 | # Visual Studio LightSwitch build output 288 | **/*.HTMLClient/GeneratedArtifacts 289 | **/*.DesktopClient/GeneratedArtifacts 290 | **/*.DesktopClient/ModelManifest.xml 291 | **/*.Server/GeneratedArtifacts 292 | **/*.Server/ModelManifest.xml 293 | _Pvt_Extensions 294 | 295 | # Paket dependency manager 296 | .paket/paket.exe 297 | paket-files/ 298 | 299 | # FAKE - F# Make 300 | .fake/ 301 | 302 | # CodeRush personal settings 303 | .cr/personal 304 | 305 | # Python Tools for Visual Studio (PTVS) 306 | __pycache__/ 307 | *.pyc 308 | 309 | # Cake - Uncomment if you are using it 310 | # tools/** 311 | # !tools/packages.config 312 | 313 | # Tabs Studio 314 | *.tss 315 | 316 | # Telerik's JustMock configuration file 317 | *.jmconfig 318 | 319 | # BizTalk build output 320 | *.btp.cs 321 | *.btm.cs 322 | *.odx.cs 323 | *.xsd.cs 324 | 325 | # OpenCover UI analysis results 326 | OpenCover/ 327 | 328 | # Azure Stream Analytics local run output 329 | ASALocalRun/ 330 | 331 | # MSBuild Binary and Structured Log 332 | *.binlog 333 | 334 | # NVidia Nsight GPU debugger configuration file 335 | *.nvuser 336 | 337 | # MFractors (Xamarin productivity tool) working folder 338 | .mfractor/ 339 | 340 | # Local History for Visual Studio 341 | .localhistory/ 342 | 343 | # BeatPulse healthcheck temp database 344 | healthchecksdb 345 | 346 | # Backup folder for Package Reference Convert tool in Visual Studio 2017 347 | MigrationBackup/ 348 | 349 | # Ionide (cross platform F# VS Code tools) working folder 350 | .ionide/ 351 | -------------------------------------------------------------------------------- /PreviewPaneExtensionSample/PreviewPaneExtensionSample/PreviewPaneExtensionSample.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | x86 7 | {52494317-8F3C-4ED1-B0C9-EA3979654352} 8 | AppContainerExe 9 | Properties 10 | PreviewPaneExtensionSample 11 | PreviewPaneExtensionSample 12 | en-US 13 | UAP 14 | 10.0.19041.0 15 | 10.0.17763.0 16 | 14 17 | 512 18 | {A5A43C5B-DE2A-4C0C-9213-0A381AF9435A};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 19 | true 20 | false 21 | 22 | 23 | true 24 | bin\x86\Debug\ 25 | DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP 26 | ;2008 27 | full 28 | x86 29 | false 30 | prompt 31 | true 32 | 33 | 34 | bin\x86\Release\ 35 | TRACE;NETFX_CORE;WINDOWS_UWP 36 | true 37 | ;2008 38 | pdbonly 39 | x86 40 | false 41 | prompt 42 | true 43 | true 44 | 45 | 46 | true 47 | bin\ARM\Debug\ 48 | DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP 49 | ;2008 50 | full 51 | ARM 52 | false 53 | prompt 54 | true 55 | 56 | 57 | bin\ARM\Release\ 58 | TRACE;NETFX_CORE;WINDOWS_UWP 59 | true 60 | ;2008 61 | pdbonly 62 | ARM 63 | false 64 | prompt 65 | true 66 | true 67 | 68 | 69 | true 70 | bin\ARM64\Debug\ 71 | DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP 72 | ;2008 73 | full 74 | ARM64 75 | false 76 | prompt 77 | true 78 | true 79 | 80 | 81 | bin\ARM64\Release\ 82 | TRACE;NETFX_CORE;WINDOWS_UWP 83 | true 84 | ;2008 85 | pdbonly 86 | ARM64 87 | false 88 | prompt 89 | true 90 | true 91 | 92 | 93 | true 94 | bin\x64\Debug\ 95 | DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP 96 | ;2008 97 | full 98 | x64 99 | false 100 | prompt 101 | true 102 | 103 | 104 | bin\x64\Release\ 105 | TRACE;NETFX_CORE;WINDOWS_UWP 106 | true 107 | ;2008 108 | pdbonly 109 | x64 110 | false 111 | prompt 112 | true 113 | true 114 | 115 | 116 | PackageReference 117 | 118 | 119 | 120 | App.xaml 121 | 122 | 123 | MainPage.xaml 124 | 125 | 126 | 127 | 128 | 129 | Designer 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | PreserveNewest 144 | 145 | 146 | 147 | 148 | MSBuild:Compile 149 | Designer 150 | 151 | 152 | MSBuild:Compile 153 | Designer 154 | 155 | 156 | 157 | 158 | 6.2.10 159 | 160 | 161 | 162 | 163 | {e12c85b3-2b31-4783-9bf0-d251a8599750} 164 | FilePreviewService 165 | 166 | 167 | 168 | 14.0 169 | 170 | 171 | 178 | --------------------------------------------------------------------------------