各种选择框
文件夹选择
1 2 3 4 5 6 7
| FolderPicker pick = new FolderPicker(); pick.FileTypeFilter.Add("*"); var folder = await pick.PickSingleFolderAsync(); if (folder != null) { TB_HexoPath.Text = folder.Path; }
|
ContentDialog
张高兴的 UWP 开发笔记:定制 ContentDialog 样式
在本地保存和加载设置
保存设置
1 2
| ApplicationDataContainer localSetting=ApplicationData.Current.RoamingSettings; localSetting.Values[key] = value;
|
加载设置
1 2
| ApplicationDataContainer localSetting=ApplicationData.Current.RoamingSettings; string value = localSetting.Values[key] as string;
|
通知消息
首先需要通过NuGet安装 Microsoft.Toolkit.Uwp.Notifications
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
| ToastContent Content = new ToastContent() { Scenario = ToastScenario.Reminder, Visual = new ToastVisual() { BindingGeneric = new ToastBindingGeneric() { Children = { new AdaptiveText(){Text = "正在等待用户完成操作..."}, new AdaptiveText(){Text = "请开启文件系统权限"}, new AdaptiveText(){Text = "随后点击下方的立即启动"} } } },
Actions = new ToastActionsCustom { Buttons = { new ToastButton("立即启动","Restart") { ActivationType =ToastActivationType.Foreground }, new ToastButtonDismiss("稍后") } } }; ToastNotificationManager.CreateToastNotifier().Show(new ToastNotification(Content.GetXml()));
|
访问其他磁盘文件权限
Package.appxmanifest 中添加权限
1 2 3 4 5 6 7 8
| <Package ... xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities" IgnorableNamespaces="uap mp rescap"> ... <Capabilities> <rescap:Capability Name="broadFileSystemAccess" /> </Capabilities>
|
判断是否有权限
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| void Method() { bool isFileAccessible = await CheckFileAccessAuthority().ConfigureAwait(false); } Task<bool> CheckFileAccessAuthority() { return Task.Run(() => { try { var folder = StorageFolder.GetFolderFromPathAsync(Environment.GetLogicalDrives().FirstOrDefault()).AsTask().Result; return true; } catch { return false; } }); }
|
进入设置开启权限
1
| await Launcher.LaunchUriAsync(new Uri("ms-settings:privacy-broadfilesystemaccess"));
|
获取APP信息
获取版本号
1
| Windows.ApplicationModel.Package.Current.Id.Version;
|
更多
UWP 应用获取各类系统、用户信息 (1) - 设备和系统的基本信息、应用包信息、用户数据账户信息和用户账户信息
获取窗口大小
获取主窗体大小
1
| Windows.UI.ViewManagement.ApplicationView.GetForCurrentView().VisibleBounds
|
获取当前窗体大小