gpt4 book ai didi

c# - c# wpf中的MessageDialog

转载 作者:行者123 更新时间:2023-12-04 16:55:52 24 4
gpt4 key购买 nike

我买了书“Heads up c#”。我使用的是 Windows 10 和 VS 2015,所以只有 WPF,但本书是为 XAML 设计的......

第 11 章要求使用这些命名空间:使用 Windows.System、Windows.Storage、Windows.UI.Popups 但我在 WPF 中找不到它们,这些用于:MessageDialog、UIcommand、IStorageFile、FileOpenPicker,有没有办法将它们添加到 WPF项目?

//编辑
感谢您的帮助,我已经为 UWP 修补了 VS,它可以工作。
但现在我的问题是scalling:
页面大小设置为 800x600,这些是列:

 <Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>

标题在第一行,内容在第二行,按钮(保存,加载)在第三行,看起来网格不存在:

Thats with normal size

After size change

在 WPF 中它有效;/

最佳答案

对于异步对话框,试试这个:

using System.Threading.Tasks;
using System;
using System.Windows;

// 1. call method with message window
ShowMyDialogWindow();

// 2. use async and await with Task, create your message window here.
public async void ShowMyDialogWindow()
{
MessageBoxResult result= await Task.Run(() => MessageBox.Show("Arre you happy?",
"My window name", MessageBoxButton.YesNoCancel));
switch (result)
{
case MessageBoxResult.None:
break;
case MessageBoxResult.Yes:
// do something
break;
case MessageBoxResult.No:
// do something
break;
default:
break;
}
// This line will be executed after windows closed you can use it for
// something (close resource, stop timer ...)
DoSomeThingHereToo();
}

// message window do not block your app, app will running other task.

关于c# - c# wpf中的MessageDialog,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39546024/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com