如何使用WindowsHost创建WPF窗口,独立于分辨率 [英] How do I make my WPF Window along with WindowsHost, resolution independent

查看:62
本文介绍了如何使用WindowsHost创建WPF窗口,独立于分辨率的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我在WPF窗口中托管了一个用户控制Win表单.Win主机的屏幕分辨率大小小于WPF Window的屏幕分辨率。( WPF窗口大小增长)

如果有任何方法可以让所有分辨率中的两个同步,请告诉我。

Hi ,

I have a User Control Win Form hosted in WPF Window.At higher screen resolution size of Win host is less than that of WPF Window.(WPF Window size grows)
Please let me know if there is any way to make two of them in Sync in all resolutions.

推荐答案

你所谓的决议不是决议;这只是像素中的屏幕尺寸。分辨率是非常不同的概念,它指的是某些系统能够将每毫米/英寸的一定数量的线分解为单独的线;它只在行话中使用,屏幕尺寸称为分辨率;我们应该避免它。



您描述的问题根本不存在。您不应使用任何控件的手动大小。在表单一侧,您可以使用 Dock Padding 属性对于所有控件,使用除 System.Windows.Forms.DockStyle.None 以外的 Dock 值,它将自动 - 大小所有布局:

https://msdn.microsoft.com/en-us/library/system.windows.forms.control.dock%28v=vs.110%29.aspx [ ^ ],

https://msdn.microsoft.com/en-us/library/system.windows.forms.dockstyle%28v=vs.110%29.aspx [ ^ ]。br />


在WPF方面,有很多布局功能,其中容器UI元素的大小由内容的大小定义,内容的大小由容器的大小定义。只有一个例子是在行或列定义中使用值Auto或*表示 ColumnWidth RowHeight 对于 System.Windows.Controls.Grid

https://msdn.microsoft.com/en-us/library/system.windows.controls.grid%28v=vs.110 %29.aspx [ ^ ],

https://msdn.microsoft.com/en-us/library/system.windows.controls.grid.rowdefinitions%28v=vs.110%29 .aspx [ ^ ],

https://msdn.microsoft.com/en-us/library/system.windows.controls.grid.columndefinitions%28v=vs.110%29 .aspx [ ^ ]。



另一个例子是 System.Windows.Controls.DockPanel

https://msdn.microsoft.com/en-us/library/system.windows.controls.dockpanel%28v=vs.110%29.aspx [ ^ ] 。



您还需要了解如何定义窗口大小:https://msdn.microsoft。 com / en-us / library / system.windows.window.sizetocontent%28v = vs.110%29.aspx [ ^ ]。



对于背景模式细节,请阅读WPF布局模型:

https://msdn.microsoft.com/en-us/library/vstudio/ms745058%28v=vs.100%29.aspx [ ^ ],

http://www.wpftutorial.net/LayoutProperties.html [ ^ ]。



设计合适布局,你永远不会遇到你描述的问题。



-SA
What you call "resolution" is not resolution; this is simply the screen size in pixel. Resolution is very different concept, it refers to the ability of some system to resolve certain number of lines per mm/inch as separate lines; it's only in jargon use screen size is called "resolution"; we should avoid it.

The problem you described simply does not exist. You should not use manual sizes of any control. On Forms side, you can use Dock and Padding properties for all controls, with the Dock values other than System.Windows.Forms.DockStyle.None, it will auto-size all layout:
https://msdn.microsoft.com/en-us/library/system.windows.forms.control.dock%28v=vs.110%29.aspx[^],
https://msdn.microsoft.com/en-us/library/system.windows.forms.dockstyle%28v=vs.110%29.aspx[^].

On WPF side, there are many layout features where the size of the container UI element is defined by the size of content, and the size of content is defined by the size of the container. Just one example is using the value "Auto" or "*" for ColumnWidth or RowHeight in row or column definitions use for the System.Windows.Controls.Grid:
https://msdn.microsoft.com/en-us/library/system.windows.controls.grid%28v=vs.110%29.aspx[^],
https://msdn.microsoft.com/en-us/library/system.windows.controls.grid.rowdefinitions%28v=vs.110%29.aspx[^],
https://msdn.microsoft.com/en-us/library/system.windows.controls.grid.columndefinitions%28v=vs.110%29.aspx[^].

Another example is System.Windows.Controls.DockPanel:
https://msdn.microsoft.com/en-us/library/system.windows.controls.dockpanel%28v=vs.110%29.aspx[^].

You also need to understand how the Window sizing is defined: https://msdn.microsoft.com/en-us/library/system.windows.window.sizetocontent%28v=vs.110%29.aspx[^].

For mode detail on background, read on WPF Layout Model:
https://msdn.microsoft.com/en-us/library/vstudio/ms745058%28v=vs.100%29.aspx[^],
http://www.wpftutorial.net/LayoutProperties.html[^].

Design proper layout, and you will never face the problem you described.

—SA


这篇关于如何使用WindowsHost创建WPF窗口,独立于分辨率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆