使用VS编写代码。
程序中使用了winform窗体对话框,所以需要引用winform窗体类。但在net 5以上,原来的方法失效。
找了半天,发现在“应用程序设置”中,勾选“为该项目启用Winform窗体”,重新编译,既可解决问题。
private void BtnSelectDirectory_Click(object sender, RoutedEventArgs e)
{
var dialog = new System.Windows.Forms.FolderBrowserDialog();
if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
txtSaveDirectory.Text = dialog.SelectedPath;
}
}
命名空间“System.Windows”中不存在类型或命名空间名“Forms”(是否缺少程序集引用?)