windows8 APP精要(2)打开文件方式

本文介绍如何在UWP应用中打开本地文件及网络资源,包括使用默认程序打开文件、显示警告提示框、提供选择程序对话框等功能,并演示了具体的实现代码。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 /// <summary>
        /// 是否采用默认关联程序打开文件
        /// </summary>
        /// <param name="withPicker"></param>
        public async void OpenFile( bool withPicker)
        {
            StorageFolder storageFolder = KnownFolders.DocumentsLibrary;
            StorageFile file = await storageFolder.CreateFileAsync("网络.pdf", CreationCollisionOption.ReplaceExisting);

            if (file != null)
            {
                if (withPicker)
                {
                    //请用户选择打开方式
                    var options = new LauncherOptions { DisplayApplicationPicker = true };
                    options.UI.PreferredPlacement = Placement.Below;
                    await Launcher.LaunchFileAsync(file, options);
                }
                else
                {
                    //直接使用默认关联程序打开
                    await Launcher.LaunchFileAsync(file);
                }
            }
        }

 

打开网络文件

string uriToLaunch = @\\"http://www.DevDiv.com\\";
 // Create a Uri object from a URI string  
 var uri = new Uri(uriToLaunch); 
 // Launch the URI 
 var success = await Windows.System.Launcher.LaunchUriAsync(uri); 

 

   // Launch a URI.
            private async void LaunchUriButton_Click(object sender, RoutedEventArgs e)
            {
                  var uri = new Uri(uriToLaunch);
                  bool success = await Windows.System.Launcher.LaunchUriAsync(uri);
            }

            // Launch a URI. Show a warning prompt.
            private async void LaunchUriWithWarningButt on_Click(object sender, RoutedEventArgs e)
            {
                  var uri = new Uri(uriToLaunch);

                  LauncherOptions options = new LauncherOptions();// Configure the warning prompt.
                  options.TreatAsUntrusted = true;

                  bool success = await Launcher.LaunchUriAsync(uri, options);
            }

            // Launch a URI. Show an Open With dialog that lets the user chose the handler to use.
            private async void LaunchUriOpenWithButton_Click(object sender, RoutedEventArgs e)
            {
                  var uri = new Uri(uriToLaunch);

                  Point openWithPosition = GetOpenWithPosition(this.LaunchUriOpenWithButton);

                  var options = new LauncherOptions();
                  options.DisplayApplicationPicker  = true;
                  options.UI.InvocationPoint = openWithPosition;
                  options.UI.PreferredPlacement = Placement.Below;

                  bool success = await Windows.System.Launcher.LaunchUriAsync(uri, options);
            }

            // The Open With dialog should be displayed just under the element that triggered it.
            private Windows.Foundation.Point GetOpenWithPosition(FrameworkElement element)
            {
                  Windows.UI.Xaml.Media.GeneralTransform buttonTransform = element.TransformToVisual(null);

                  Point desiredLocation = buttonTransform.TransformPoint(new Point());
                  desiredLocation.X = desiredLocation.X + element.ActualWidth / 2;
                  desiredLocation.Y = desiredLocation.Y + element.ActualHeight;

                  return desiredLocation;
            }

 

内容概要:2025年大宗商品市场展望报告由世界银行发布,分析了能源、农业、金属和矿物、贵金属以及化肥等多个主要商品类别的市场发展与前景。报告指出,由于全球经济增长放缓和贸易紧张加剧,2025年大宗商品价格预计总体下降12%,2026年进一步下降5%,达到六年来的最低点。油价预计2025年平均为每桶64美元,2026年降至60美元,主要受全球石油消费放缓和供应增加的影响。农业商品价格预计2025年基本稳定,2026年下降3%,其中粮食和原材料价格分别下降7%和2%,但饮料价格上涨20%。金属价格预计2025年下降10%,2026年再降3%,特别是铜和铝价格将显著下跌。贵金属如黄金和白银因避险需求强劲,预计价格将继续上涨。报告还特别关注了疫情后大宗商品周期的变化,指出周期变得更短、更剧烈,主要受到宏观经济冲击、极端天气事件和地缘政治冲突的影响。 适用人群:对全球经济趋势、大宗商品市场动态及其对不同经济体影响感兴趣的政策制定者、投资者、分析师及研究机构。 使用场景及目标:①帮助政策制定者评估全球经济增长放缓对大宗商品市场的影响,从而调整经济政策;②为投资者提供有关未来大宗商品价格走势的风险提示,以便进行投资决策;③协助分析师和研究机构深入理解疫情后大宗商品市场的周期特征,识别潜在的投资机会和风险。 其他说明:报告强调,全球经济增长放缓、贸易紧张加剧以及地缘政治不确定性是影响大宗商品价格的主要因素。此外,极端天气事件和能源转型也对农业和能源商品市场产生了深远影响。报告呼吁各方关注这些结构性变化,并采取相应的风险管理措施。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值