Foreword
With the release of .net core 3.0, WPF can also be used on the core platform. The current WPF does not support cross-platform, and can only be used on the Windows platform. If you want to experience WPF cross-platform development, you can visit the open source project Avalonia. However, the current WPF can already meet most of our usage needs, after all, it is very cool to use core to develop. This means that it is not necessary to install the .net framework dependent environment on the user’s machine, and the software released in an independent manner can be directly run after being copied to any Windows.
Start
When we started a new WPF journey with excitement, we found that the FolderBrowserDialog could not be used, even if we Entering reference using System.Windows.Forms;
also found that the editor reported an error:
When trying to add an assembly to the reference as usual, I found that the option of assembly is no longer available in the reference manager.
Browsing online for a long time, there is no Find any useful information. However, this issue was mentioned in an issue of dotnet/wpf. In the discussion, it was said that the folder dialog box in Windows forms could be used, but it did not say how to use it. And this is exactly the problem we encountered.
Solve
We might as well look at the problem in another way and check how the source project files are composed. Open the wpf project file and find that it is extremely concise.
WinExe netcoreapp3.0 true
This is also a major change in core 3.0. All default references will no longer appear in the project file. The same is true when we look at the forms project file. The only difference is that the switch UseWPF
has been changed to
. After trying to write the switch into the wpf project file, I found that the editor reported an error and cancelled it. And the folder dialog can also be used. This means that wpf and forms can still coexist. And users can switch to wpf project by changing the switch from the forms project.
////// Interaction logic for MainWindow.xaml/// public partial class MainWindow{ public MainWindow() {InitializeComponent();} private void OpenFolderDialog() {var fbd = new FolderBrowserDialog(); fbd.ShowDialog(); }}
Summary
Although this article is extremely simple, it is now If there are few Chinese materials for core 3.0, I believe it will be helpful for novices. Therefore, I hope to help you.