Review of the previous chapter: Avalonia UI, a cross platform framework of. Net: filling the hole and pointing to the North (1): familiar with UI operation
This article will describe some considerations including but not limited to Avalonia and all windows to Linux cross platform development:
1、 Path problem
1. In normal WPF (and windows application software) development, accessing files (if you are lazy) (such as me) usually uses string splicing directly
For example, we can access the data in the software directory\ xxx.txt Document:
string path = AppDomain.CurrentDomain.BaseDirectory+"\Data\xxx.txt";
It works perfectly on windows
If you bring this habit to Linux, if you can’t find the file, it’s OK
(explodes in an instant)
This is because:
In windows, the file path is represented by a horizontal backslash: \\ xxx.txt
In Linux, the file path is represented by a backslash: / for example, / home/ xxx.txt
When you use the word \ \ “in Linux, Linux will think that is the file name.. and the file cannot be found or deleted in windows. (don’t ask me how to know)
Therefore, the following method is recommended for docking path strings:
Path.Combine(AppDomain.CurrentDomain.BaseDirectory,"Data","xxx.txt");
2. How to get a special folder (my documents and so on) on Linux correctly
Everybody knowsEnvironment.GetFolderPath This method, however, is not normal on Linux:
MSDN said:
But my test results on deepin Linux are not like this
Mydocuments outputs / root
Personal output: Home / twlm (my user name)
So if you want to get the “My Documents” folder correctly, you can use:
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal),"Documents", "XXXX");
And judge the platform and return the correct path on different platforms
public static string MyDocumentsPath { get {
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
return Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal),"Music", "LemonAppCoreDownload");
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
return Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyMusic), "LemonAppCoreDownload");
Else return "; // if I don't have a Mac OSX machine, I won't do it. Please refer to the documentation
} }
2、 Network access
When I tested on deepin, a very strange exception came out:
Like an exception that cannot load the assembly, it calls the webclientBut change toHttpWebRequestIt’s gone
When I released, I turned on stand-alone – > assembly clippingIt may also be the problem here
The same problem occurs with bass audio decoder (Introduction)
When you useBass.BASS_ When the streamcreateurl method accesses the music file on the URL, whether the network is smooth or the link is accessible or not, the timeout timeout error will be reported
3、 Font rendering problems
I don’t have much problem with deepin
You can refer to the following documents: https://www.cnblogs.com/drzhong/p/11678701.html