• win10 uwp 关联文件


    有时候应用需要打开后缀名为x的文件,那么如何从文件打开应用?

    <!--more-->
    <!-- csdn -->

    首先,需要打开 Package.appxmanifest

    添加一个功能,需要添加最少有名称,文件类型。

    上面的图就是我添加jpg 的方法,我的应用可以打开jpg,我也有一个应用是需要的。

    这个就是 UWP图床:https://www.microsoft.com/store/apps/9nblggh562r2

    添加完,打开App.xaml.cs

    添加一个函数

            protected override void OnFileActivated(FileActivatedEventArgs args)
            {
                base.OnFileActivated(args);
            }

    需要对他做一点修改

            protected override void OnFileActivated(FileActivatedEventArgs args)
            {
                var file = args.Files[0];
                Frame frame = Window.Current.Content as Frame;
                if (frame == null)
                {
                    frame = new Frame();
                    Window.Current.Content = frame;
                }
                frame.Navigate(typeof(MainPage), file);
                 Window.Current.Activate();
     }

    这里的file可能是空。

    页面跳转就是这样,页面传入可以是 StorageFile。

    直接显示在 MainPage ,如果需要显示在别的窗口,当然也不是对你有难度。

    最好的方法是使用MVVM 参见:http://lindexi.oschina.io/lindexi/post/win10-uwp-MVVM%E5%85%A5%E9%97%A8/

    我没有在博客说如何传参,但是这个对大家也不难。

    打开 MainPage.xaml 写一个Image

                <Image x:Name="Image"></Image>
    

    打开 xaml.cs ,把app启动的file显示

            protected override async void OnNavigatedTo(NavigationEventArgs e)
            {
                var file = e.Parameter as StorageFile;
                if (file != null)
                {
                    using (var stream = await file.OpenAsync(FileAccessMode.Read))
                    {
                        BitmapImage img = new BitmapImage();
                        await img.SetSourceAsync(stream);
                        Image.Source = img;
                    }
                }
            }

    UWP 从文件显示图片很简单,打开放在img就好。

    于是打开一个jpg,用这个应用,可以看到,就是简单代码就可以。

    一个好看的应用,需要在关联文件加上图片。

    看到txt 文件,有一个图片,这个图片,如果应用可以加上一个图片,这个图片就是设置默认应用加上。

    但是个人开发者好像不能关联文件。

    知识共享许可协议
    本作品采用知识共享署名-非商业性使用-相同方式共享 4.0 国际许可协议进行许可。欢迎转载、使用、重新发布,但务必保留文章署名林德熙(包含链接:http://blog.csdn.net/lindexi_gd ),不得用于商业目的,基于本文修改后的作品务必以相同的许可发布。如有任何疑问,请与我联系

    <script type="text/javascript"> $(function () { $('pre.prettyprint code').each(function () { var lines = $(this).text().split(' ').length; var $numbering = $('<ul/>').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i <= lines; i++) { $numbering.append($('<li/>').text(i)); }; $numbering.fadeIn(1700); }); }); </script>
  • 相关阅读:
    charles连接手机抓包
    charles抓包,打断点,连接手机抓包
    python读写文件相关内容
    python基础操作
    页面刷新 方法总结 JSP刷新[转]
    .html 页面修改成 .jsp 后缀后中文乱码解决办法。
    bootstrap 学习笔记(5)---- 图片和响应式工具
    bootstrap学习大纲
    bootstrap 学习笔记(4)---- 按钮
    bootstrap 学习笔记(3)---- 代码
  • 原文地址:https://www.cnblogs.com/lindexi/p/6949668.html
Copyright © 2020-2023  润新知