win10 uwp App-to-app communication 应用通信

最后更新于:2022-04-01 20:23:48

这篇文章都是乱说的,如果觉得有不好的,可以发我邮箱  应用之间需要相互的发送信息,就是我们经常用的分享  ![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-04-08_5707637a780ad.jpg)  有个人看到一个网页很好,于是就希望把这个网页发送到邮件,那么这样的话就是使用应用通信。  因为每个应用都是不能访问其他应用数据,所以需要通信可以使用启动内置应用,文件关联应用。 ## 发送数据 创建一个event 可以在用户发送,共享发送 ~~~ DataTransferManager data_transfer_manager = DataTransferManager.GetForCurrentView(); data_transfer_manager.DataRequested += DataTransferManager_DataRequested; ~~~ 当DataRequested,应用收到一个DataRequest,这个是DataPackage可以在里面写你要发送的信息。DataPackage必须写标题和数据,如果有描述也写 ~~~ private static void DataTransferManager_DataRequested(DataTransferManager sender, DataRequestedEventArgs args) { DataRequest request = args.Request; } ~~~ 可以共享数据: * 纯文本 * url * HTML * 文本 * 图片 * 文件 * 自己弄的我也不知道是什么的可以共享的 ~~~ //文本 request.Data.SetText(text); //uri //request.Data.SetUri(uri);过时 request.Data.SetWebLink(uri); //html request.Data.SetHtmlFormat(html); request.Data.SetRtf(text); //文件 request.Data.SetStorageItems(file); //图片 request.Data.SetBitmap(bitmap); ~~~ 我们需要和用户说我们在做的数据 ~~~ request.Data.Properties.Title = "标题"; request.Data.Properties.Description = "我的博客blog.csdn.net/lindexi_gd"; ~~~ ![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-04-08_5707637a8dc57.jpg)  开始通信 ~~~ DataTransferManager.ShowShareUI(); ~~~ 有时候我们需要等待一些操作需要时间,不能马上就分享,我们可以使用 ~~~ request.Data.Properties.Title = "标题"; request.Data.Properties.Description = "我的博客blog.csdn.net/lindexi_gd"; request.Data.SetDataProvider(StandardDataFormats.Bitmap, (data_provider_request) => { DataProviderDeferral deferral = data_provider_request.GetDeferral(); //做时间比较长的操作 //一般可以把操作内容放try,因为操作内容主要是io,有出错 //如果放在try,把deferral.Complete();finally //try //{ // //操作 //} //finally //{ // //deferral.Complete(); //} deferral.Complete(); }); ~~~ 要接受其他的app我们需要设置`requestData.Properties.ContentSourceApplicationLink = ApplicationLink;`  ApplicationLink是`new Uri("ms-sdk-sharesourcecs:navigate?page=" + 页面名);`  要接受其他的app我们需要设置  ![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-04-08_5707637a9ee3e.jpg) ![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-04-08_5707637ab2d23.jpg)  我们在说明写:林德熙博客  但说明其实没有什么用,主要是数据格式才是需要我们选择,在上也看到我们可以分享的数据有多种格式,那么满足格式的分享就会在分享看到我们的应用。  ![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-04-08_5707637ac5299.jpg)  新建一个页面接分享,因为我想不到这个叫什么,我就放在MainPage  导航到MainPage就是分享打开  页面传参数可以使用,`Frame frame.Navigate`(页面,参数) ~~~ protected override void OnNavigatedTo(NavigationEventArgs e) { } ~~~ 在App.xaml.cs ~~~ protected override void OnShareTargetActivated(ShareTargetActivatedEventArgs args) { Frame rootFrame = Window.Current.Content as Frame; if (rootFrame == null) { rootFrame=new Frame(); Window.Current.Content = rootFrame;//http://blog.csdn.net/lindexi_gd } rootFrame.Navigate(typeof (MainPage), args.ShareOperation); Window.Current.Activate(); } ~~~ 我们可以在OnNavigatedTo拿分享 ~~~ protected override async void OnNavigatedTo(NavigationEventArgs e) { ShareOperation share_operation = e.Parameter as ShareOperation; if (share_operation == null) { return; } //标题 string shared_data_title = share_operation.Data.Properties.Title; string shared_data_description = share_operation.Data.Properties.Description; Uri url = share_operation.Data.Properties.ContentSourceWebLink; Uri application_link = share_operation.Data.Properties.ContentSourceApplicationLink; //图像 RandomAccessStreamReference thumbnail = share_operation.Data.Properties.Thumbnail; //应用名称 string application_name = share_operation.Data.Properties.ApplicationName; //数据 //判断存在,如果不存在我们 if (share_operation.Data.Contains(StandardDataFormats.WebLink)) { Uri web_link =await share_operation.Data.GetWebLinkAsync(); } } ~~~ 当我们做完可以告诉`share_operation.ReportCompleted();`  如果错了可以告诉发送我们接受错  分享成功经常返回一个链接,我们把一个东西分享到百度云,那么我们可以拿到一个链接百度云,可以发送,这个`QuickLink` `QuickLink`·我们需要标题,图标,id ~~~ QuickLink quickLinkInfo = new QuickLink() { Id = QuickLinkId, Title = QuickLinkTitle, SupportedFileTypes = { "*" }, SupportedDataFormats = { StandardDataFormats.Text, StandardDataFormats.WebLink, StandardDataFormats.ApplicationLink, StandardDataFormats.Bitmap,//http://blog.csdn.net/lindexi_gd StandardDataFormats.StorageItems, StandardDataFormats.Html }, Thumbnail = thumbnail, }; share_operation.ReportCompleted(quickLinkInfo); ~~~ ## 文件启动 我们需要关联  ![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-04-08_5707637ad9f94.jpg) 在app.xaml.cs ~~~ protected override void OnFileActivated(FileActivatedEventArgs args) { // args.Files } ~~~ Files包含文件可以拿来 博客:[http://blog.csdn.net/lindexi_gd](http://blog.csdn.net/lindexi_gd) 原文:[https://msdn.microsoft.com/en-us/windows/uwp/app-to-app/index](https://msdn.microsoft.com/en-us/windows/uwp/app-to-app/index)
';

win10 UWP Controls by function

最后更新于:2022-04-01 20:23:46

Windows的XAML UI框架提供了很多控件,支持用户界面开发库。其中一些有可视化,一些布局。  一些控件例子:[https://github.com/Microsoft/Windows-universal-samples/tree/master/Samples/XamlUIBasics](https://github.com/Microsoft/Windows-universal-samples/tree/master/Samples/XamlUIBasics) 我现在做的一个中文版的,很多都是照着微软写,除了注释 我们先学微软做一个简单的frame,新建Page,  里面放title和跳转页 ~~~ public class page { public page() { } /// /// 跳转页 /// public Type navigate { set { _navigate = value; } get { return _navigate; } } /// /// 页面名 /// public string title { set { _title = value; } get { return _title; } } private Type _navigate; private string _title; } ~~~ 我们需要把所有页放到一个类,本来这个类可以不弄,直接放Page  使用索引  最后我还是想给宝资通打广告  弄了一个类,本来应该叫page管理器,我叫baozitong  输入title返回type ~~~ public static Type page(string title) { foreach (var temp in _page) { if (temp.title == title) { return temp.navigate; } } return null; } public static List _page { set; get; }=new List() { new page() { title = "appbar", navigate = typeof(appbar) } }; ~~~ 每次添加page可以在baozitong._page new page 界面splitview ~~~ ~~~ ~~~ private void nagivate(object sender, SelectionChangedEventArgs e) { //跳转navigate frame.Navigate(((sender as ListView).SelectedItem as page).navigate); } ~~~ ## Appbars and commands ### App bar 用于显示应用程序特定命令的工具栏。 ### App bar button 使用app bar风格按钮  一个简单的按钮 ~~~ ~~~ ![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-04-08_570763769cc39.jpg)  我们可以加上内容 ~~~ ~~~ ![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-04-08_57076376ae0f0.jpg)  我们可以在按钮加浮出 ~~~ ~~~ ![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-04-08_57076376bf84a.jpg) ![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-04-08_57076376d2dd9.jpg) ### App bar separator 命令栏中的命令组。  如果我们有很多按钮,我们可以使用 ~~~ ~~~ ![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-04-08_57076376e656a.jpg) ### App bar toggle button 开关命名命令栏 ### Command bar 一种专门处理命令按钮栏按钮 我们把刚才的按钮放在`` ~~~ ~~~ ![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-04-08_570763770263a.jpg) 我们也看到最后的按钮,如果有一些用不到,但是有用 ~~~ ~~~ ![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-04-08_5707637714cf0.jpg) ## Buttons ### Button 响应用户输入和点击事件。 ~~~ ~~~ ![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-04-08_5707637725931.jpg) 按钮点击可以使用`X:Bind` ### Hyperlink 超链接 ~~~ 博客发在csdn ,没有授权红黑转载,没有授权推酷转载 ~~~ ![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-04-08_5707637749283.jpg) ### Repeat button 用户点击不停响应。 ## Collection/data controls ### Flip view 幻灯片播放 ~~~ ~~~ ![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-04-08_5707637761d18.jpg) [http://www.cnblogs.com/Damai-Pang/p/5201206.html](http://www.cnblogs.com/Damai-Pang/p/5201206.html) ### Grid view 行列布局,可以水平滚动控件。 ### Items control 提供UI指定数据模板 ### List view 在一个列表上的项目的集合,可以垂直滚动控件  我们做一个viewmodel ~~~ public class viewmodel : notify_property { public viewmodel() { } } ~~~ 我们依列表 ~~~ public ObservableCollection lindexi { set; get; } = new ObservableCollection() { "林德熙", "csdn" }; ~~~ ~~~ ~~~ ![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-04-08_57076377c1426.jpg) ## Date and time controls ### Calendar date picker 日历日期选择器  ![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-04-08_57076377d303b.png)  ![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-04-08_57076377e7c3c.jpg) ### Calendar view 日程表,让用户选择日期  ![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-04-08_5707637802a3f.jpg) ### Time picker 用户选择一个时间  ![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-04-08_57076378123aa.jpg) ## Flyouts ### Flyout 显示一条消息 ~~~ ~~~ ![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-04-08_570763782352e.jpg) ### Menu flyout 暂时显示命令或列出选项给用户选择 ~~~ ~~~ ### Popup menu 弹出自己写的菜单 ### Tooltip 提示 ~~~
';

Win10 UWP Intro to controls and events

最后更新于:2022-04-01 20:23:43

这篇翻译,如果有不对可以发邮箱 为创建页面,可以通过按钮,TextBox输入,组合框来显示数据,获得用户输入。添加一个控件可以使用三个关键步骤: * 添加一个控件到界面 * 设置控件属性,高度,宽度,颜色 * 添加控件的事件 ## 添加控件 可以使用以下任意方式添加控件 * 使用界面直接拖控件,Blend直接在工具箱把控件拖到界面  ![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-04-08_570763751a798.png) 点击Button,拖动Button界面  ![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-04-08_570763756acb9.jpg) * 用Xaml编辑`` * 代码添加控件 在visual studio可以使用工具箱、Xaml编辑器、设计器,属性窗口 * 工具箱  ![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-04-08_5707637583e47.png) * Xaml编辑器  ![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-04-08_570763759d466.jpg) * 设计器  ![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-04-08_57076375be48c.jpg) * 属性窗口  ![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-04-08_57076375dce72.jpg) 工具箱显示很多可以用在软件的控件,可以拖动控件到界面,可以双击控件,控件就会自动添加到软件。 双击TextBox ~~~ ~~~ ## 命名控件 为了在代码改变控件,可以给控件名字,`x:Name`后面写控件名称,控件名称不能重复,不能数字开头 可以使用属性来命名控件 点击控件,在属性可以看到  ![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-04-08_57076376006d9.jpg) 在名称写上控件名 ## 设置控件属性 可以在属性选择控件属性  ![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-04-08_57076376006d9.jpg) 可以编辑Xaml写控件  ![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-04-08_5707637620763.jpg) 如果你设置了一个你不要,可以重设属性  ![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-04-08_5707637634e43.png)  点击重新设置 设置颜色可以使用下面的颜色表  ![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-04-08_57076376494ca.png) 在Xaml写Visual studio在你按下一个键就会提示 ![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-04-08_570763765e451.png) ## 控件事件 每个控件都有很多事件,可以使用Xaml,属性创建事件,创建事件的方法是事件处理,参见:[https://msdn.microsoft.com/windows/uwp/xaml-platform/events-and-routed-events-overview](https://msdn.microsoft.com/windows/uwp/xaml-platform/events-and-routed-events-overview)  创建事件可以在属性  ![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-04-08_5707637675a0f.png)  选择事件,写名称,按回车,就会到cs,事件处理第一个参数是发送者,引用对象,第二个是事件数据  我们创建一个Click ~~~ private void Button_Click(object sender, Windows.UI.Xaml.RoutedEventArgs e) { Button button=sender as Button;//sender 发送者 } ~~~ 如果有给按钮名称,可以在代码  ![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-04-08_5707637688062.png) 原文:[https://msdn.microsoft.com/windows/uwp/controls-and-patterns/controls-and-events-intro](https://msdn.microsoft.com/windows/uwp/controls-and-patterns/controls-and-events-intro)
';

win10 UWP GET Post

最后更新于:2022-04-01 20:23:41

win10 应用应该是要有访问网络,网络现在最多的是使用GET,Post,简单的使用,可以用网络的数据:获得博客的访问量。 在使用网络,我们需要设置`Package.appxmanifest` 网络请求使用GET,首先有要访问的网站 ~~~ string url = "http://blog.csdn.net/lindexi_gd/article/details/50830924"; //url是我一篇博客,win10 UWP Hmac,我很多博客都是读书笔记 ~~~ WebRequest是请求基类,需要使用`WebRequest.Create(url);` ~~~ request.Method = "GET"; ~~~ UWP 的Header设置 ~~~ request.Headers["Cookie"] ~~~ 接受需要一个函数 AsyncCallback `private void response_callback(IAsyncResult result)` ~~~ request.BeginGetResponse(response_callback, request); ~~~ response_callback接受信息`HttpWebRequest http_web_request = (HttpWebRequest)result.AsyncState;` ~~~ WebResponse web_response = http_web_request.EndGetResponse(result); using (Stream stream = web_response.GetResponseStream()) { using (StreamReader reader = new StreamReader(stream)) { string content = reader.ReadToEnd(); } } ~~~ 我们需要对content进行正则 正则可以看 [正则快速](https://github.com/lindexi/lindexi_gd/blob/master/%E5%8D%9A%E5%AE%A2/%E6%AD%A3%E5%88%99%E8%A1%A8%E8%BE%BE%E5%BC%8F30%E5%88%86%E9%92%9F%E5%85%A5%E9%97%A8%E6%95%99%E7%A8%8B.md) ~~~ Regex regex = new Regex(@"(\d\d\d人阅读)"); string str = regex.Match(content).Result("阅读:$1"); reminder(str); ~~~ 如果使用UI,直接使用会出现 ![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-04-08_57076374e0ab0.jpg) 我们写函数 ~~~ private async void reminder(string str) { await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { tb.Text += str; }); } ~~~ 网络很容易就异常 ~~~ catch (WebException e) { switch (e.Status) { case WebExceptionStatus.CacheEntryNotFound: break; case WebExceptionStatus.ConnectFailure: reminder("ConnectFailure:远程服务器连接失败"); break; case WebExceptionStatus.ConnectionClosed: break; case WebExceptionStatus.KeepAliveFailure: break; case WebExceptionStatus.MessageLengthLimitExceeded: reminder("MessageLengthLimitExceeded 网络请求消息长度受到限制"); break; case WebExceptionStatus.NameResolutionFailure: break; case WebExceptionStatus.Pending: reminder("Pending 内部异步挂起"); break; case WebExceptionStatus.PipelineFailure: break; case WebExceptionStatus.ProtocolError: break; case WebExceptionStatus.ProxyNameResolutionFailure: break; case WebExceptionStatus.ReceiveFailure: break; case WebExceptionStatus.RequestCanceled: break; case WebExceptionStatus.RequestProhibitedByCachePolicy: break; case WebExceptionStatus.RequestProhibitedByProxy: break; case WebExceptionStatus.SecureChannelFailure: break; case WebExceptionStatus.SendFailure: break; case WebExceptionStatus.ServerProtocolViolation: break; case WebExceptionStatus.Success: break; case WebExceptionStatus.Timeout: break; case WebExceptionStatus.TrustFailure: break; case WebExceptionStatus.UnknownError: break; } reminder(e.Message); } ~~~ post需要把`request.Method = "POST";` 传输在`request.BeginGetRequestStream(respeonse_streamCallback, request);` ~~~ private void respeonse_streamCallback(IAsyncResult result) { HttpWebRequest http_web_request = (HttpWebRequest) result.AsyncState; using (Stream stream=http_web_request.EndGetRequestStream(result)) { //发送byte string str = "c"; byte[] buffer = Encoding.UTF8.GetBytes(str); stream.Write(buffer,0,buffer.Length); } http_web_request.BeginGetResponse(response_callback, http_web_request); } ~~~ 简单方法 ~~~ HttpClient http=new HttpClient(); reminder(await http.GetStringAsync(new Uri(url))); ~~~ 获整个对象 ~~~ HttpResponseMessage response = await http.GetAsync(new Uri(url)); reminder(await response.Content.ReadAsStringAsync()); ~~~ ~~~ HttpClient http = new HttpClient(); HttpStringContent http_string =new HttpStringContent("a"); HttpResponseMessage response = await http.PostAsync(new Uri(url), http_string); string str = await response.Content.ReadAsStringAsync(); reminder(str); ~~~ ~~~ HttpClient http = new HttpClient(); InMemoryRandomAccessStream memory =new InMemoryRandomAccessStream(); HttpStreamContent stream=new HttpStreamContent(memory); HttpResponseMessage response = await http.PostAsync(new Uri(url), stream); string str = await response.Content.ReadAsStringAsync(); reminder(str); ~~~ ~~~ HttpClient http = new HttpClient(); InMemoryRandomAccessStream memory = new InMemoryRandomAccessStream(); HttpStreamContent stream = new HttpStreamContent(memory); HttpRequestMessage request=new HttpRequestMessage(HttpMethod.Post,new Uri(url)); request.Content = stream; HttpResponseMessage response = await http.SendRequestAsync(request); string str = await response.Content.ReadAsStringAsync(); ~~~ 看到有人说CSDN博客访问统计是Cache,如果我们要有很多访问,可以使用 ~~~ filter.CacheControl.WriteBehavior = HttpCacheWriteBehavior.NoCache; await Task.Run(() => { reminder("\n"); WebRequest request = WebRequest.Create(url); request.Method = "GET"; request.Headers["Cookie"] = string.Empty; request.BeginGetResponse(response_callback, request); }); ~~~ ![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-04-08_5707637502841.jpg) 我把之前写的一个刷500 cookie可以使用`HttpBaseProtocolFilter` 设置cookie ~~~ HttpCookie cookie = new HttpCookie("名称", "blog.csdn.net", "/") { Value = "a", }; filter.CookieManager.SetCookie(cookie, false); ~~~ 这写的不好,我将会写网络编程,这一篇会写容易的我的博客授权发在win10.me 原文:[http://www.cnblogs.com/linzheng/](http://www.cnblogs.com/linzheng/) 博客:[blog.csdn.net/lindexi_gd](http://blog.csdn.net/lindexi_gd/article/details/blog.csdn.net/lindexi_gd)
';

win10 UWP Hmac

最后更新于:2022-04-01 20:23:39

HMAC是密钥相关的哈希运算消息认证码,输入密钥和信息。  在uwp,Hmac在很多网络使用,我最近写qiniu SDK,把原来C#改为UWP,需要使用HMAC。 上传文件 ~~~
~~~ 需要凭据,凭据有上传策略 ~~~ string str_alg_name = MacAlgorithmNames.HmacSha1; MacAlgorithmProvider obj_mac_prov = MacAlgorithmProvider.OpenAlgorithm(str_alg_name); IBuffer buff_msg = CryptographicBuffer.CreateFromByteArray(path_and_query_bytes); IBuffer buff_key_material = CryptographicBuffer.CreateFromByteArray(mac.SecretKey); CryptographicKey hmac_key = obj_mac_prov.CreateKey(buff_key_material); IBuffer hmac = CryptographicEngine.Sign(hmac_key, buff_msg); byte[] digest = hmac.ToArray(); ~~~ `string str_alg_name = MacAlgorithmNames.HmacSha1;`微软有AesCmac、HmacMd5、HmacSha1、HmacSha256、HmacSha384、HmacSha512 `MacAlgorithmProvider.OpenAlgorithm`传入使用算法 Hmac输入buffer,byte`CryptographicBuffer.CreateFromByteArray` Hmac密钥`obj_mac_prov.CreateKey(buff_key_material)`
';

win10 UWP MessageDialog 和 ContentDialog

最后更新于:2022-04-01 20:23:36

我之前开发一个软件 winMarkdown,这个软件在关闭需要提示用户还没有保存东西,需要保存,如果用户选择退出,那么把数据存放。 在Metro程序中,没有传统的窗口,当我们要用需要交互的消息提示时,在Win8时代,引入了一个MessageDialog来取代常用的MessageBox。 我在MainPage,挂起`App.Current.Suspending += suspend;` ~~~ private async void suspend(object sender, Windows.ApplicationModel.SuspendingEventArgs e) { SuspendingDeferral deferral = e.SuspendingOperation.GetDeferral(); MessageDialog message_dialog = new MessageDialog("当前还在运行,确定退出", "退出"); message_dialog.Commands.Add(new UICommand("确定", cmd => { }, "退出")); message_dialog.Commands.Add(new UICommand("取消", cmd => { })); message_dialog.DefaultCommandIndex = 0; message_dialog.CancelCommandIndex = 1; IUICommand result = await message_dialog.ShowAsync(); if (result.Id as string == "退出") { } deferral.Complete(); } ~~~ `SuspendingDeferral deferral = e.SuspendingOperation.GetDeferral();`挂起还要做,直到`deferral.Complete();` ~~~ MessageDialog message_dialog = new MessageDialog("当前还在运行,确定退出", "退出"); message_dialog.Commands.Add(new UICommand("确定", cmd => { }, "退出")); message_dialog.Commands.Add(new UICommand("取消", cmd => { })); ~~~ 两个按钮,一个确定,一个取消,可以UICommand ID作为点击后,是哪个按钮点击 ~~~ MessageDialog.DefaultCommandIndex按ESC选择按钮 MessageDialog.CancelCommandIndex按enter按钮 ~~~ ~~~ IUICommand result = await message_dialog.ShowAsync(); if (result.Id as string == "退出") { } ~~~ 程序要调试挂起,需要生命周期,点击挂起  ![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-04-08_5707637499af5.jpg) 我们按enter就会点击确定 而我们对于MessageDialog功能还是觉得不够,ContentDialog可以定义复杂的Xaml自定义 我们把MessageDialog换ContentDialog ~~~ ContentDialog content_dialog = new ContentDialog() { Title = "退出", Content = "当前还在运行,确定退出", PrimaryButtonText = "确定", SecondaryButtonText = "取消", FullSizeDesired = true, }; content_dialog.PrimaryButtonClick += (_s, _e) => { }; await content_dialog.ShowAsync(); ~~~ ![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-04-08_57076374b17bb.jpg) ~~~ ~~~ ~~~ ContentDialog content_dialog = new ContentDialog() { Title = "退出", Content = new content(), PrimaryButtonText = "确定", SecondaryButtonText = "取消", FullSizeDesired = false, }; content_dialog.PrimaryButtonClick += (_s, _e) => { }; await content_dialog.ShowAsync(); ~~~ ![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-04-08_57076374c7977.jpg) 参见:  [http://www.cnblogs.com/TianFang/p/4857205.html](http://www.cnblogs.com/TianFang/p/4857205.html)
';

win10 UWP RSS阅读器

最后更新于:2022-04-01 20:23:34

RSS简易信息聚合(也叫聚合内容)是一种RSS基于XML标准,在互联网上被广泛采用的内容包装和投递协议。RSS(Really Simple Syndication)是一种描述和同步网站内容的格式,是使用最广泛的XML应用。RSS搭建了信息迅速传播的一个技术平台,使得每个人都成为潜在的信息提供者。发布一个RSS文件后,这个RSS Feed中包含的信息就能直接被其他站点调用,而且由于这些数据都是标准的XML格式,所以也能在其他的终端和服务中使用,是一种描述和同步网站内容的格式。RSS可以是以下三个解释的其中一个: Really Simple Syndication;RDF (Resource Description Framework) Site Summary; Rich Site Summary。但其实这三个解释都是指同一种Syndication的技术。 今天在win10.me看到一个rss,不知道是什么东西,打开看到  ![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-04-08_570763733bd57.jpg) 于是在网上查了RSS,又在微软官网看到[https://msdn.microsoft.com/zh-cn/library/windows/apps/mt429379.aspx](https://msdn.microsoft.com/zh-cn/library/windows/apps/mt429379.aspx) 林政的书也有说过,不过他是用HttpWebRequest 我的rss是使用SyndicationClient  先创建SyndicationClient ~~~ Windows.Web.Syndication.SyndicationClient client = new Windows.Web.Syndication.SyndicationClient(); Windows.Web.Syndication.SyndicationFeed feed; ~~~ 因为输URL可能是错的,所以微软就用try catch ~~~ //uri写在外面,为了在try之外不会说找不到变量 Uri uri = null; //uri字符串 string uriString = "http://www.win10.me/?feed=rss2"; try { uri = new Uri(uriString); } catch (Exception ex) { throw ex; } ~~~ 网络请求有很多异常,我们放在try ~~~ try { //模拟http // 如果没有设置可能出错 client.SetRequestHeader("User-Agent", "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; WOW64; Trident/6.0)"); feed = await client.RetrieveFeedAsync(uri); foreach (Windows.Web.Syndication.SyndicationItem item in feed.Items) { displayCurrentItem(item); } } catch (Exception ex) { // Handle the exception here. } ~~~ 我们写一个函数处理每个SyndicationItem ~~~ private void displayCurrentItem(Windows.Web.Syndication.SyndicationItem item) { string itemTitle = item.Title == null ? "No title" : item.Title.Text; string itemLink = item.Links == null ? "No link" : item.Links.FirstOrDefault().ToString(); string itemContent = item.Content == null ? "No content" : item.Content.Text; string itemSummary = item.Summary.Text + ""; reminder = itemTitle + "\n" + itemLink + "\n" + itemContent+"\n"+itemSummary+"\n"; } ~~~ reminder是通知显示,把每个不为空的值放在StringBuilder  ![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-04-08_5707637391de9.jpg) 看起来很多html,我们可以用WebUtility,Regex来得到文本 我们可以做一个显示标题,然后点击显示内容 建一个类rssstr,这个类存放rss标题和内容 在viewModel 一个列表`ObservableCollection` 界面MainPage ~~~
';

win10 UWP 你写我读

最后更新于:2022-04-01 20:23:32

想要电脑读出我们写的内容,在win10,很简单  其实这个技术在windows7就有了,但是现在win10让写出一个你写我读的软件很简单。  我们需要一个类`MediaElement`来播放,因为windows10的Markdown软件用的不是很好,所有我自己写一个。  这个软件我用了你写我读,[https://github.com/lindexi/Markdown](https://github.com/lindexi/Markdown)  ![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-04-08_57076372e3040.jpg) 点击![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-04-08_57076373025d7.jpg) 读出文本 在使用`SpeechSynthesizer`需要代码功能点麦克风 ![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-04-08_5707637311ee0.jpg) ![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-04-08_570763732677b.jpg) 代码我放在model  代码很少就可以你写我读 ~~~ private async void speech(string str, MediaElement media_element) { SpeechSynthesizer synthesizer = new SpeechSynthesizer(); SpeechSynthesisStream stream = await synthesizer.SynthesizeTextToStreamAsync(str); media_element.SetSource(stream, stream.ContentType); media_element.Play(); } ~~~ 实例化`SpeechSynthesizer`,使用`SynthesizeTextToStreamAsync`把文本变为流 可以使用`MediaElement`播放,`MediaElement`播放需要把流和格式放到`MediaElement` ~~~ media_element.Play(); ~~~ ~~~ ~~~ Volume 声音 参考:[http://www.cnblogs.com/tcjiaan/](http://www.cnblogs.com/tcjiaan/)
';

win10 UWP 单元测试

最后更新于:2022-04-01 20:23:30

我们在写代码的时候不能保证我们写出来的代码是正确的,所以我们经常要单元测试。  单元测试和重构都是在做完一个小小函数一般就要进行一次,越早做就越好,可以比较早发现问题,这时我们还记得我们写的内容,不过比重构好的是,重构我们经常不知道要叫什么名字,而单元测试反而就比较简单。 右击解决方案,添加新项目  ![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-04-08_57076372551f4.jpg) C#->Windows->通用->单元测试应用  ![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-04-08_5707637269047.jpg) 命名我是叫 测试 在新建单元测试右击引用  ![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-04-08_5707637269047.jpg) 把工程引用  ![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-04-08_570763728dbd2.jpg) 打开测试项目 一般测试哪个类我就会新建一个类名称和要测试类相同,类里面函数和要测试函数名相同。 我在做一个windows Markdown,里面有函数把剪贴的文本覆盖Textbox选文本,我不知道这个函数写的是不是对,于是我就在单元测试,新建一个类 测试函数所在的类是winmain,所以在单元测试新建一个类winmain 在新建类加上 ~~~ using Microsoft.VisualStudio.TestPlatform.UnitTestFramework; ~~~ 在类定义前 ~~~ [TestClass] ~~~ 在类里面加函数 clipboard_substitution  函数需要在函数前 ~~~ [TestMethod] ~~~ 我的函数需要测试输入一个文本是否会把选择的string替换输入文本 我们在测试单元写测试输入 ~~~ var view =new produproperty.ViewModel.winmain(null); string text = "要替换文本"; //把替换两个字替换为string view.text = text; view.select = 1; view.select_length = 2; view.clipboard_substitution("string"); ~~~ 然后写Assert ~~~ Assert.AreEqual("要string文本",view.text); ~~~ 右击运行  ![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-04-08_57076372a144f.jpg) 可以在运行 所有测试  ![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-04-08_57076372b7264.jpg) 测试通过  ![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-04-08_57076372c9923.jpg) 我们还要做一些诡异测试 出现错误Index and length must refer to a location within the string.  这样就是我们函数有问题 如果通过了我们才可以说我们代码可以提交 Assert是返回结果true方法是测试通过,如果是其他就不通过,Assert可以有方法 | 方法 | 描述 | | --- | --- | | AreEqual | 两个值是否相等 | | AreNotEqual | 两个值不相等 | | AreNotSame | 两个值不相同 | | AreSame | 两个值相同 |
';

win10 UWP 标题栏后退

最后更新于:2022-04-01 20:23:27

设置里,标题栏有后退按钮  ![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-04-08_570763723398e.jpg)  在win平板,可以有后退键,手机也有  pc可以在标题栏 ![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-04-08_570763724332e.jpg) 在`OnLaunched` ~~~ //最后 Windows.UI.Core.SystemNavigationManager.GetForCurrentView().BackRequested += BackRequested; Windows.UI.Core.SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility = Windows.UI.Core.AppViewBackButtonVisibility.Visible; ~~~ BackRequested后退方法
';

win10 UWP 圆形等待

最后更新于:2022-04-01 20:23:25

看到一个圆形好像微软ProgressRing [![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-04-08_57076371ac895.gif)](https://github.com/lindexi/lindexi_gd/blob/master/%E5%8D%9A%E5%AE%A2/image/0_1321962945yCXF.gif) 我们可以用自定义控件 按ctrl+shift+a 用户控件 我们可以用Rectangle做圆形边 只要Rectangle RadiusX>0圆角 因为每个Rectangle 都一样,我们可以资源 ~~~ ~~~ 设置Rectangle 在中间 资源设置需要选TargetType 我们是Rectangle ~~~ ~~~ 因为不知道这个要叫什么,就用右击资源 [![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-04-08_57076371beab9.png)](https://github.com/lindexi/lindexi_gd/blob/master/%E5%8D%9A%E5%AE%A2/image/20161291187294.png) [![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-04-08_57076371d4af6.png)](https://github.com/lindexi/lindexi_gd/blob/master/%E5%8D%9A%E5%AE%A2/image/20161291182112.png) vs默认RectangleStyle1 每个项需要 ~~~ ~~~ 设置中间 ~~~ ~~~ 看起来Rectangle很大 [![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-04-08_57076371e8e21.png)](https://github.com/lindexi/lindexi_gd/blob/master/%E5%8D%9A%E5%AE%A2/image/201612911107238.png) 把Height为20 ~~~ ~~~ [![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-04-08_57076372028e0.png)](https://github.com/lindexi/lindexi_gd/blob/master/%E5%8D%9A%E5%AE%A2/image/201612911111820.png) 全部资源 ~~~ ~~~ 我们做10个Rectangle 使用RectangleStyle1 在Rectangle `style="{StaticResource RectangleStyle1}"` 中间是白色比较好 ~~~ ~~~ [![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-04-08_57076372137c1.png)](https://github.com/lindexi/lindexi_gd/blob/master/%E5%8D%9A%E5%AE%A2/image/201612911134992.png) 每个Rectangle 一个名字 我们想要xaml动,可以 ~~~ ~~~ Forever一直动 使用控件 ~~~ ~~~ [![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-04-08_5707637223123.png)](https://github.com/lindexi/lindexi_gd/blob/master/%E5%8D%9A%E5%AE%A2/image/201612911161755.png) 全部 ~~~ round.xaml ~~~ ~~~ MainPage ~~~ 代码:[https://github.com/lindexi/lindexi_gd/tree/master/roundload](https://github.com/lindexi/lindexi_gd/tree/master/roundload) 参考:[http://blog.csdn.net/qqamoon/article/details/7001693](http://blog.csdn.net/qqamoon/article/details/7001693) 本文:http://blog.csdn.net/lindexi_gd [](http://blog.csdn.net/lindexi_gd/article/details/50606261#)[](http://blog.csdn.net/lindexi_gd/article/details/50606261# "分享到QQ空间")[](http://blog.csdn.net/lindexi_gd/article/details/50606261# "分享到新浪微博")[](http://blog.csdn.net/lindexi_gd/article/details/50606261# "分享到腾讯微博")[](http://blog.csdn.net/lindexi_gd/article/details/50606261# "分享到人人网")[](http://blog.csdn.net/lindexi_gd/article/details/50606261# "分享到微信")
';

win10 UWP 九幽数据分析

最后更新于:2022-04-01 20:23:23

九幽数据统计是统计和分析数据来源,用户使用,先申请账号 [http://www.windows.sc](http://www.windows.sc/) [![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-04-08_570763710b71f.png)](https://github.com/lindexi/lindexi_gd/blob/master/%E5%8D%9A%E5%AE%A2/image/201611220331168.png) 创建应用 [![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-04-08_57076371217b6.png)](https://github.com/lindexi/lindexi_gd/blob/master/%E5%8D%9A%E5%AE%A2/image/201611220345291.png) 图片要72*72 记密钥 [![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-04-08_5707637136446.png)](https://github.com/lindexi/lindexi_gd/blob/master/%E5%8D%9A%E5%AE%A2/image/201611220348976.png) 在项目Nuget [![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-04-08_57076371528d2.png)](https://github.com/lindexi/lindexi_gd/blob/master/%E5%8D%9A%E5%AE%A2/image/201611220373361.png) [![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-04-08_5707637171362.png)](https://github.com/lindexi/lindexi_gd/blob/master/%E5%8D%9A%E5%AE%A2/image/20161122037747.png) 在App.xaml.cs ~~~ public App() { Microsoft.ApplicationInsights.WindowsAppInitializer.InitializeAsync( Microsoft.ApplicationInsights.WindowsCollectors.Metadata | Microsoft.ApplicationInsights.WindowsCollectors.Session); this.InitializeComponent(); this.Suspending += OnSuspending; this.Resuming += App_Resuming; } private void App_Resuming(object sender, object e) { track(); } protected override void OnActivated(IActivatedEventArgs args) { base.OnActivated(args); track(); } private async void track() { await JYAnalyticsUniversal.JYAnalytics.StartTrackAsync("你的key"); } ~~~ 在OnLaunched加 ~~~ track(); ~~~ 在OnSuspending加 ~~~ private async void OnSuspending(object sender, SuspendingEventArgs e) { var deferral = e.SuspendingOperation.GetDeferral(); //TODO: 保存应用程序状态并停止任何后台活动 await JYAnalyticsUniversal.JYAnalytics.EndTrackAsync(); //需注意此处代码位置不可更改 deferral.Complete(); } ~~~ 运行,等待九幽 页面统计 ~~~ protected override void OnNavigatedFrom(Windows.UI.Xaml.Navigation.NavigationEventArgs e) { base.OnNavigatedFrom(e); JYAnalytics.TrackPageEnd("main_page"); } protected override void OnNavigatedTo(Windows.UI.Xaml.Navigation.NavigationEventArgs e) { base.OnNavigatedTo(e); JYAnalytics.TrackPageStart("main_page"); } ~~~ 统计次数 ~~~ JYAnalytics.TrackEvent("StartTimes"); ~~~ 统计StartTimes次数 ~~~ string eventId=“open";//当前统计的事件 string lable="打开blog.csdn.net/lindexi_gd";//描述当前id JYAnalytics.TrackEvent(eventId,lable); ~~~ 统计错误 ~~~ string error=”“; JYAnalytics.TrackError(error); ~~~ 在Package.appxmanifest功能 Internet(客户端服务器)使用 [![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-04-08_5707637194596.png)](https://github.com/lindexi/lindexi_gd/blob/master/%E5%8D%9A%E5%AE%A2/image/201611220506879.png) http://blog.csdn.net/lindexi_gd
';

win10 UWP 应用设置

最后更新于:2022-04-01 20:23:21

win10 UWP 应用设置 简单的把设置需要的,放到微软自带的LocalSettings LocalSettings.Values可以存放几乎所有数据 如果需要存放复合数据,一个设置项是由多个值组成,可以使用ApplicationDataCompositeValue将多个合并。 存放一个string ~~~ string str { set { ApplicationData.Current.LocalSettings.Values["str"] = value; } get { object temp; if (ApplicationData.Current.LocalSettings.Values.TryGetValue("width", out temp)) { return temp as string; } } } ~~~ 如果设置在LocalSettings让程序太乱,有很多变量名称一样,可以使用新的ApplicationDataContainer ~~~ string str = ""; var t = ApplicationData.Current.LocalSettings.CreateContainer("str", ApplicationDataCreateDisposition.Always); t.Values["str"] = str; str = t.Values["str"] as string; ~~~
';

win10 UWP Markdown 含源代码

最后更新于:2022-04-01 20:23:18

Windows下没有比较好的Markdown编辑器 我就自己写一个 csdn的Markdown很好,就是我需要截图保存有麻烦 需要把我的截图保存在本地,然后上传 这个过程比较麻烦 csdn的图没法外链 我想把自己的博客放到github,发现都没有图片 我自己写了的,可以把截图保存为图片,放到用户位置 然后插入`![](image/file.png)` 拖入图片也插入`![](image/file.png)` ![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-04-08_5707636e37eec.png) 界面有编辑和设置 编辑由TopAppBar,TextBox作为输入和TextBlock显示 拖入文件可以使用Drop 在Grid写Drop="{x:Bind view.dropimg}" DragOver="Grid_DragOver" Grid要AllowDrop="True" 在MainPage.xaml.cs ~~~ private void Grid_DragOver(object sender, DragEventArgs e) { e.AcceptedOperation = Windows.ApplicationModel.DataTransfer.DataPackageOperation.Copy; e.DragUIOverride.Caption = "打开"; e.Handled = true; } ~~~ ![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-04-08_5707636e608fa.png) 在viewModel public async void dropimg(object sender, Windows.UI.Xaml.DragEventArgs e) dropimg 处理拖进来的DataPackageView ~~~ var defer = e.GetDeferral(); try { DataPackageView dataView = e.DataView; string str = await _m.clipboard(dataView); tianjia(str); } finally { defer.Complete(); } ~~~ 文件有 MainPage.xaml MainPage.xaml.cs option.xaml option.xaml.cs viewModel.cs model.cs notify_property.cs 其中notify_property.cs提供继承通知UI改变值 model包括 正在编辑文件file 保存位置folder 其中folder根据StorageApplicationPermissions.FutureAccessList获得用户位置。 可以访问的路径不多,因为一个程序可以访问文件路径多,不安全。如果每次放在一个不是程序目录的位置,都要用户设置,很麻烦。在用户第一次使用,让用户选择一个位置,然后应用程序可以直接访问用户选择的这个,不用每次都选择。 用户输入text 标题 name 其中text和name都是public string _text; ![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-04-08_5707636e828de.png) 这样是在viewModel使用,可以OnPropertyChanged(); writetext是用户能输入,在没有设置用户位置,不能输入 _open是否打开 public async Task clipboard(DataPackageView con) 处理剪贴板和拖入内容 本来我是处理剪贴板,因为拖入也是DataPackageView ~~~ public async Task clipboard(DataPackageView con) { string str = string.Empty; //文本 if (con.Contains(StandardDataFormats.Text)) { str = await con.GetTextAsync(); //tianjiatext(str); return str; } //图片 if (con.Contains(StandardDataFormats.Bitmap)) { RandomAccessStreamReference img = await con.GetBitmapAsync(); var imgstream = await img.OpenReadAsync(); Windows.UI.Xaml.Media.Imaging.BitmapImage bitmap = new Windows.UI.Xaml.Media.Imaging.BitmapImage(); bitmap.SetSource(imgstream); Windows.UI.Xaml.Media.Imaging.WriteableBitmap src = new Windows.UI.Xaml.Media.Imaging.WriteableBitmap(bitmap.PixelWidth, bitmap.PixelHeight); src.SetSource(imgstream); Windows.Graphics.Imaging.BitmapDecoder decoder = await Windows.Graphics.Imaging.BitmapDecoder.CreateAsync(imgstream); Windows.Graphics.Imaging.PixelDataProvider pxprd = await decoder.GetPixelDataAsync(Windows.Graphics.Imaging.BitmapPixelFormat.Bgra8, Windows.Graphics.Imaging.BitmapAlphaMode.Straight, new Windows.Graphics.Imaging.BitmapTransform(), Windows.Graphics.Imaging.ExifOrientationMode.RespectExifOrientation, Windows.Graphics.Imaging.ColorManagementMode.DoNotColorManage); byte[] buffer = pxprd.DetachPixelData(); str = "image"; StorageFolder folder = await _folder.GetFolderAsync(str); StorageFile file = await folder.CreateFileAsync(DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + ".png", CreationCollisionOption.GenerateUniqueName); using (var fileStream = await file.OpenAsync(FileAccessMode.ReadWrite)) { var encoder = await Windows.Graphics.Imaging.BitmapEncoder.CreateAsync(Windows.Graphics.Imaging.BitmapEncoder.PngEncoderId, fileStream); encoder.SetPixelData(Windows.Graphics.Imaging.BitmapPixelFormat.Bgra8, Windows.Graphics.Imaging.BitmapAlphaMode.Straight, decoder.PixelWidth, decoder.PixelHeight, decoder.DpiX, decoder.DpiY, buffer); await encoder.FlushAsync(); str = $"![这里写图片描述](image/{file.Name})"; } } //文件 if (con.Contains(StandardDataFormats.StorageItems)) { var filelist = await con.GetStorageItemsAsync(); StorageFile file = filelist.OfType().First(); return await imgfolder(file); } return str; } ~~~ 返回string是因为要把str插入到text,需要有Textbox光标插入 插入文件 ~~~ public async Task imgfolder(StorageFile file) { string str = "image"; StorageFolder image = null; try { image = await _folder.GetFolderAsync(str); } catch { } if (image == null) { image = await _folder.CreateFolderAsync(str, CreationCollisionOption.OpenIfExists); } file = await file.CopyAsync(image, file.Name, NameCollisionOption.GenerateUniqueName); if (file.FileType == ".png" || file.FileType == ".jpg") { str = $"![这里写图片描述](image/{file.Name})"; return str; } else { str = $"[{file.Name}](image/{file.Name})"; return str; } } ~~~ 开始我没有用文件 拖入和剪贴板只用第一个文件 public async void accessfolder(StorageFolder folder) 更改用户位置 public async void storage() 保存 在程序运行 ~~~ folder = await Windows.Storage.AccessCache.StorageApplicationPermissions.FutureAccessList.GetFolderAsync(Windows.Storage.AccessCache.StorageApplicationPermissions.FutureAccessList.Entries[0].Token); ~~~ viewModel.cs ~~~ public string text { set { _m._text = value; OnPropertyChanged(); } get { return _m._text; } } public string name { set { _m._name = value; OnPropertyChanged(); } get { return _m._name; } } ~~~ 本来绑Textbox SelectionStart SelectionStart错误 要用SelectionStart,只能public Action selectchange; 在MainPage.xaml.cs ~~~ private void selectchange(int select, int selecti) { text.SelectionStart = select; text.SelectionLength = selecti; } ~~~ 因为选择可以把`![这里写图片描述](image/{file.Name})` ![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-04-08_5707636e9b4ba.png) select Textbox选择的插入 clipboard 保存剪贴板 storage 保存 accessfolder 更改用户位置 ~~~ public async void accessfolder() { FolderPicker pick = new FolderPicker(); pick.FileTypeFilter.Add("*"); StorageFolder folder = await pick.PickSingleFolderAsync(); if (folder != null) { _m.accessfolder(folder); } addressfolder = string.Empty; } ~~~ model _m ~~~ private void tianjia(string str) ~~~ 把str添加text MainPage.xaml ~~~ public sealed partial class MainPage { viewModel view; public MainPage() { this.InitializeComponent(); text.Paste += Text_Paste; } private void Text_Paste(object sender, TextControlPasteEventArgs e) { view.clipboard(e); } private void Grid_DragOver(object sender, DragEventArgs e) { e.AcceptedOperation = Windows.ApplicationModel.DataTransfer.DataPackageOperation.Copy; e.DragUIOverride.Caption = "打开"; e.Handled = true; } private void text_SelectionChanged(object sender, RoutedEventArgs e) { view.select = text.SelectionStart; } private void selectchange(int select, int selecti) { text.SelectionStart = select; text.SelectionLength = selecti; } private bool _ctrl; private void text_KeyDown(object sender, KeyRoutedEventArgs e) { if (e.Key.Equals(Windows.System.VirtualKey.Control)) { _ctrl = true; } else if (e.Key == Windows.System.VirtualKey.V && _ctrl) { } if (_ctrl) { if (e.Key == Windows.System.VirtualKey.Z) { } } e.Handled = true; } private void text_KeyUp(object sender, KeyRoutedEventArgs e) { if (e.Key.Equals(Windows.System.VirtualKey.Control)) { _ctrl = false; } } private void option(object sender, RoutedEventArgs e) { view.storage(); Frame frame = Window.Current.Content as Frame; frame.Navigate(typeof(option), view); } protected override void OnNavigatedTo(NavigationEventArgs e) { base.OnNavigatedTo(e); if (e.Parameter is viewModel) { view = e.Parameter as viewModel; DataContext = view; } else { view = new viewModel(); view.selectchange = selectchange; this.DataContext = view; } } } ~~~ ![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-04-08_5707636ead98c.png) ### [](https://github.com/lindexi/lindexi_gd/blob/master/%E5%8D%9A%E5%AE%A2/win10%20UWP%20Markdown%20%E5%90%AB%E6%BA%90%E4%BB%A3%E7%A0%81.md#发布)发布 [https://dev.windows.com/zh-cn](https://dev.windows.com/zh-cn) 登录 ![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-04-08_5707636ec8b9e.png) 在我的应用 ![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-04-08_5707636edc01f.png) 填名字 ![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-04-08_5707636ef142c.png) 本来想写Markdown 不过自己做的不是很好,不敢,就写win 有人发了Markdown应用 ![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-04-08_5707636f20659.png) 点击开始提交 ![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-04-08_5707636f30a78.png) 价格免费 ![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-04-08_5707636f4a180.png) 在visual studio ![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-04-08_5707636f5c820.png) 关联 ![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-04-08_5707636f788e8.png) ![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-04-08_5707636f9f8ad.png) ![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-04-08_5707636fb7f45.png) 选择创建的Markdown ![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-04-08_5707636fc8d93.png) 得到 produproperty_StoreKey.pfx 在属性 ![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-04-08_5707636fdd321.png) 没有密码 ![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-04-08_57076370022df.png) ![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-04-08_5707637012d36.png) ![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-04-08_570763702cff7.png) ![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-04-08_57076370493cf.png) 配置 ![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-04-08_570763706067a.png) ![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-04-08_570763707caf6.png) 把produproperty_1.1.0.0_x86_x64_arm_bundle.appxupload上传 ![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-04-08_570763709c5fb.png) ![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-04-08_57076370bf591.png) ![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-04-08_57076370ddb27.png) https://code.csdn.net/lindexi_gd/lindexi_gd/tree/master/%E5%8D%9A%E5%AE%A2/win10%20UWP%20Markdown%20%E5%90%AB%E6%BA%90%E4%BB%A3%E7%A0%81.md 源代码 https://github.com/lindexi/Markdown
';

win10 UWP button

最后更新于:2022-04-01 20:23:16

button有很多和wpf一样,可以看《深入浅出WPF》 我们可以在button的click写上 ~~~ ~~~ 我们可以修改鼠标在按钮上的样子 button可以设置属性,使用资源 资源可以写在页面 ~~~ ~~~ 所有按钮使用同样式 ~~~ ~~~ 按钮的属性用`` 按钮的背景 ~~~ ~~~ 指定一个样式,key ~~~ ~~~ ~~~ ~~~ ![这里写图片描述](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-04-08_5707636d92e4a.jpg) 显示图片 ~~~ ~~~
';

win10 UWP 申请微软开发者

最后更新于:2022-04-01 20:23:14

申请微软开发者可以到[https://dev.windows.com/zh-cn/programs/join](https://dev.windows.com/zh-cn/programs/join) 如果是学生,先去[http://www.dreamspark.com/](http://www.dreamspark.com/) 如果是英文,点student,中文点学生 ![这里写图片描述](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-04-08_5707636c0980f.jpg "") 点击创建账号 ![这里写图片描述](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-04-08_5707636c41932.jpg "") 在创建账户的页面,填写DreamSpark认证账户的相关信息,填写完全后点击继续验证 ![这里写图片描述](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-04-08_5707636c622c7.jpg "") 在学生身份页面,如果有edu邮箱可以验证,如果没有可以传自己的学生证 如果没有得到他们验证,可以去网上买一个edu 点击windows开发者账号 点获得代码 复制代码 下面注册不论是学生还是不是[https://dev.windows.com/registration](https://dev.windows.com/registration) 填写个人信息 在付款账户 ![这里写图片描述](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-04-08_5707636c7b9f9.jpg "") 粘贴刚才复制的代码 如果没有输入visa卡 visa卡不能用虚拟visa卡 可以在网上找人代付 网上卖的开发者账号不要买
';

win10 UWP 获取系统信息

最后更新于:2022-04-01 20:23:12

获取系统信息 ~~~ Windows.System.Profile.AnalyticsVersionInfo analyticsVersion = Windows.System.Profile.AnalyticsInfo.VersionInfo; reminder = analyticsVersion.DeviceFamily; ulong v = ulong.Parse(Windows.System.Profile.AnalyticsInfo.VersionInfo.DeviceFamilyVersion); ulong v1 = ( v & 0xFFFF000000000000L ) >> 48; ulong v2 = ( v & 0x0000FFFF00000000L ) >> 32; ulong v3 = ( v & 0x00000000FFFF0000L ) >> 16; ulong v4 = ( v & 0x000000000000FFFFL ); reminder = $"{v1}.{v2}.{v3}.{v4}"; Windows.ApplicationModel.Package package = Windows.ApplicationModel.Package.Current; reminder = package.Id.Architecture.ToString(); reminder = package.DisplayName; EasClientDeviceInformation eas = new EasClientDeviceInformation(); reminder= eas.SystemManufacturer; ~~~ reminder把字符串输出到textbox Windows.Desktop 10.0.10586.29 X86 参考:[https://www.suchan.cz/2015/08/uwp-quick-tip-getting-device-os-and-app-info/](https://www.suchan.cz/2015/08/uwp-quick-tip-getting-device-os-and-app-info/)
';

win10 UWP FlipView

最后更新于:2022-04-01 20:23:09

FlipView 可以让用户逐个浏览的项目集合 ~~~ ~~~ ![这里写图片描述](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-04-08_5707636ba7c6b.jpg "") 上下滚动 ~~~ ~~~ 自动 FlipView x:Name=”xf” 在MainPage.xaml.cs ~~~ DispatcherTimer time = new DispatcherTimer(); time.Interval = new TimeSpan(0,0,1); time.Tick += Time_Tick; time.Start(); ~~~ ~~~ private void Time_Tick(object sender , object e) { int i = xf.SelectedIndex; i++; if (i >= xf.Items.Count) { i = 0; } xf.SelectedIndex = i; } ~~~
';

RichEditBox 使用自定义菜单

最后更新于:2022-04-01 20:23:07

老周:当RichEditBox控件的上下文菜单即将弹出时,会引发ContextMenuOpening事件,我们需要处理该事件,并且将e.Handled属性设置为true,这样才能阻止默认上下文菜单的弹出 在RichEditBox控件上声明附加的菜单项 ~~~ ~~~ 处理OnContextMenuOpening ~~~ private void OnContextMenuOpening(object sender , ContextMenuEventArgs e) { //阻止弹出默认的上下文菜单,然后,调用ShowAt方法在指定的坐标处打开菜单 e.Handled = true; MenuFlyout menu = FlyoutBase.GetAttachedFlyout(redit) as MenuFlyout; menu?.ShowAt(redit , new Point(e.CursorLeft , e.CursorTop)); } ~~~ 处理复制粘贴 ~~~ private void OnCopy(object sender , RoutedEventArgs e) { //复制 redit.Document.Selection.Copy(); } private void OnCut(object sender , RoutedEventArgs e) { //剪切 redit.Document.Selection.Cut(); } private void OnPaste(object sender , RoutedEventArgs e) { //粘贴 redit.Document.Selection.Paste(0); //Paste 要在粘贴操作中使用的剪贴板格式。零表示最佳格式 } ~~~ 处理OnFontSize ~~~ /// /// 设置字体 /// /// /// private void OnFontSize(object sender , RoutedEventArgs e) { MenuFlyoutItem item = sender as MenuFlyoutItem; // 获取字号 float size = Convert.ToSingle(item.Tag); redit.Document.Selection.CharacterFormat.Size = size; } ~~~ ~~~ /// /// 加粗 /// /// /// private void OnBold(object sender , RoutedEventArgs e) { //using Windows.UI.Text; ToggleMenuFlyoutItem item = sender as ToggleMenuFlyoutItem; redit.Document.Selection.CharacterFormat.Bold = item.IsChecked ? FormatEffect.On : FormatEffect.Off; } private void OnUnderline(object sender , RoutedEventArgs e) { MenuFlyoutItem item = sender as MenuFlyoutItem; int x = Convert.ToInt32(item.Tag); UnderlineType unlinetp; switch (x) { case -1: // 无 unlinetp = UnderlineType.None; break; case 0: // 单实线 unlinetp = UnderlineType.Single; break; case 1: // 双实线 unlinetp = UnderlineType.Double; break; case 2: // 虚线 unlinetp = UnderlineType.Dash; break; default: unlinetp = UnderlineType.None; break; } redit.Document.Selection.CharacterFormat.Underline = unlinetp; } ~~~ ~~~ private void OnTinct(object sender , RoutedEventArgs e) { MenuFlyoutItem item = sender as MenuFlyoutItem; string tinct = item.Tag as string; Windows.UI.Color color = new Windows.UI.Color(); switch (tinct) { case "黑色": color= Windows.UI.Colors.Black; break; case "蓝色": color = Windows.UI.Colors.Blue; break; case "白色": color = Windows.UI.Colors.White; break; default: break; } redit.Document.Selection.CharacterFormat.BackgroundColor = color; } ~~~ 颜色在Windows.UI.Color 里面代码都是抄老周的 ![这里写图片描述](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-04-08_5707636b8545f.jpg "") 参考:[http://www.cnblogs.com/tcjiaan/p/4937301.html](http://www.cnblogs.com/tcjiaan/p/4937301.html)
';

win10 uwp 装机必备应用 含源代码

最后更新于:2022-04-01 20:23:05

zhxilin大神说[http://www.cnblogs.com/zhxilin/p/4819372.html](http://www.cnblogs.com/zhxilin/p/4819372.html)这文章说到了使用`await Windows.System.Launcher.LaunchUriAsync(new Uri(uri));` 打开应用商店 我想到了装机必备的一个软件 大概界面 ![这里写图片描述](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-04-08_5707636a9823d.jpg "") 求轻喷 我设计了MainPage.xaml拥有两个Frame 单例model 从[https://www.microsoft.com/zh-cn/store/top-free/apps/pc](https://www.microsoft.com/zh-cn/store/top-free/apps/pc)得到软件图片 ![这里写图片描述](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-04-08_5707636ab3513.jpg "") Button可以设置Content为Grid ~~~ ~~~ button设置大小和图片一样,就可以把图片填到button作为按钮 右击获得应用软件QQ的ProductId, ProductId是点击链接最后的 ![这里写图片描述](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-04-08_5707636ac55f2.jpg "") 9wzdncrfj1ps 使用 ~~~ string uri = "ms-windows-store://pdp/?ProductId=9wzdncrfj1ps"; await Windows.System.Launcher.LaunchUriAsync(new Uri(uri)); ~~~ 在按钮写` ~~~ movie.xaml ~~~ ~~~ 没有使用比较多的东西,简单单例,按钮,frame,GridView,没有使用bind,动画 margin可以使用”10”,我都是使用”10,10,10,10”,虽然好多写法可以简单,让代码变少,也不会容易出错,但是没有那么多,只是做一个看到的想到的好的东西,虽然这个应该发布是不会的,但是也有一些想不开的也许就发出来,有人想要。不过这样只是在博客可以这样说,实际的软件这样开发,根本做不到,因为没有那么多人都知道我的想法,知道了也不会开发出来,除了技术还有的是做出来是他想的。 也没有那些跳转出来的,好看的,我设计看起来没有一点好,本来想做一个好看的天蓝,最后成了上面的那个 ![这里写图片描述](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-04-08_5707636b56df7.jpg "") 需要的技术很少 做出来可以是一个装机必备,不知有谁想到这么简单技术做出的,可以卖软件,不知道有谁要,挂个价格100 代码:[https://code.csdn.net/lindexi_gd/lindexi_gd/tree/master/classifyapp](https://code.csdn.net/lindexi_gd/lindexi_gd/tree/master/classifyapp) 参考:[https://msdn.microsoft.com/en-us/library/windows/apps/mt228343.aspx](https://msdn.microsoft.com/en-us/library/windows/apps/mt228343.aspx)
';