In .NET Framework 4.6.2 the FormattedText() is Obsoleted, how can i fixed it

二次信任 提交于 2019-12-03 22:59:46
Leguanjoe

You need to calculate the DPI of your monitor, see: How can I get the DPI in WPF?

In Addition, with .Net 4.6.2 come new APIs to handle the DPI awareness, so the above methods might be deprecated (e.g. VisualTreeHelper.GetDpi()). See https://blogs.msdn.microsoft.com/dotnet/2016/08/02/announcing-net-framework-4-6-2/ Here is some example code and a Userguide: https://github.com/Microsoft/WPF-Samples/tree/master/PerMonitorDPI

IMHO this pararameter has been added so that your program can be dragged between monitors with different DPIs and still is scaled correctly.

From FromattedText declaration: pixelsPerDip: The Pixels Per Density Independent Pixel value, which is the equivalent of the scale factor. For example, if the DPI of a screen is 120 (or 1.25 because 120/96 = 1.25) , 1.25 pixel per density independent pixel is drawn. DIP is the unit of measurement used by WPF to be independent of device resolution and DPIs.

If you just have 1 monitor and therefore don't need any DPI changed event handling, use the following for example in the OnLoaded() event of your Window (or in your constructor):

var pixelsPerDip = VisualTreeHelper.GetDpi(this).PixelsPerDip;

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!