Olyd.Wpf.DpiAutoScale 1.0.0

dotnet add package Olyd.Wpf.DpiAutoScale --version 1.0.0                
NuGet\Install-Package Olyd.Wpf.DpiAutoScale -Version 1.0.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Olyd.Wpf.DpiAutoScale" Version="1.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Olyd.Wpf.DpiAutoScale --version 1.0.0                
#r "nuget: Olyd.Wpf.DpiAutoScale, 1.0.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Olyd.Wpf.DpiAutoScale as a Cake Addin
#addin nuget:?package=Olyd.Wpf.DpiAutoScale&version=1.0.0

// Install Olyd.Wpf.DpiAutoScale as a Cake Tool
#tool nuget:?package=Olyd.Wpf.DpiAutoScale&version=1.0.0                

Olyd.Wpf.DpiAutoScale

WPF应用程序,通过添加屏幕级别的DPI感知模式,结合Viewbox控件,实现不同DPI下,显示的实际分辨率相同的效果

注意:目前仅支持NoResize的窗体

使用步骤

  1. WPF项目添加 app.manifest,并打开DPI感知模式

add manifest

 
 <application xmlns="urn:schemas-microsoft-com:asm.v3">
  <windowsSettings>
   <dpiAwareness xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">PerMonitorV2</dpiAwareness>
   <dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true/pm</dpiAware>
  </windowsSettings>
 </application>
  1. 窗体的Content必须是 Viewbox
<Window>
    <Viewbox Stretch="UniformToFill">
    
    </Viewbox>
</Window>
  1. Window 继承 IAutoScale 接口

需要提供 ChildWidth & ChildHeight & ChildMargin 具体值 ChildWindow 必须正确指向 实现 RaiseDpiResized 方法,可以在这里实现一些尺寸变化后的方法

  1. Window 构造函数中调用 this.InitAutoScale() 方法
Product Compatible and additional computed target framework versions.
.NET net6.0-windows7.0 is compatible.  net7.0-windows was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Olyd.Wpf.DpiAutoScale:

Package Downloads
Olyd.Wpf.Guide

Wpf 新手引导

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.0 97 12/11/2024