在WPF 4.0中何时应使用SnapsToDevicePixels? [英] When should I use SnapsToDevicePixels in WPF 4.0?

查看:126
本文介绍了在WPF 4.0中何时应使用SnapsToDevicePixels?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以建议在WPF 4.0中何时使用 SnapsToDevicePixels 的准则吗?

Can anyone suggest a guideline on when to use SnapsToDevicePixels in WPF 4.0?

仅应使用偶尔在整个App中出现问题,仅在某些控件上还是什么?

Should it only be used occasionally if there is an issue, liberally throughout an App, only on certain controls or what?

推荐答案

Spencer和Martin的很好答案关于何时对齐像素。

Good answers by Spencer and Martin as to the when to align your pixels.

关于方式:我还要指出应该在WPF 4.0中 尝试使用属性 UseLayoutRounding 而不是 SnapsToDevicePixels

As to the how: I would also point out that one should in WPF 4.0 try using the property UseLayoutRounding instead of SnapsToDevicePixels.

UseLayoutRounding 使您正在做的事情与Silverlight兼容( SnapsToDevicePixels 在Silverlight中不可用)...并且Microsoft还鼓励在 SnapsToDevicePixels UseLayoutRounding >在其文档

UseLayoutRounding makes what you are doing compatible with Silverlight (SnapsToDevicePixels is not available in Silverlight) ... and Microsoft is also encouraging the use of UseLayoutRounding over SnapsToDevicePixels in its documentation.

两者之间有什么区别?好吧,一个很大的不同是 UseLayoutRounding 在布局阶段发生,而 SnapsToDevicePixels 在渲染阶段发生。这使我推测 UseLayoutRounding 可能是一种性能更高的方法(不过,我尚未证实这一点)。

What is the difference between the two? Well, one big difference is that UseLayoutRounding occurs during the layout phase while SnapsToDevicePixels occurs during the render phase. This makes me speculate that UseLayoutRounding is probably a more performant way to go (I haven't confirmed this, though).

话虽如此,仍然有理由使用 SnapsToDevicePixels 。实际上,MSDN文档指向其中之一。我还要补充一点:只有使用 SnapsToDevicePixels 才能使用准则进行精确控制。

All that being said, there will still be reasons to use SnapsToDevicePixels. In fact, the MSDN documentation points to one. I will add another: it is only with SnapsToDevicePixels that you can use guidelines for precise control.

这里有一些有关此问题的资源(即像素捕捉和图像,文本和视觉效果的清晰度):

Here are some resources on this matter (i.e. pixel snapping and clarity with images, text, and visuals):

  • The MSDN Documentation for the UIElement.SnapsToDevicePixels Property.
  • The MSDN Documentation for the FrameworkElement.UseLayoutRounding Property.
  • Here is the old, classic post by Dwayne Need on blurry images.
  • Sometimes BitmapScalingMode helps with image clarity.
  • A great blog post that shows you how to actually use SnapsToDevicePixels. It can be tricky.
  • A blog post by the WPF Text team about all the different improvements they added to WPF 4.0 in order to help text clarity.
  • Another blog post by the WPF Text team on layout rounding.

嘿。我知道我的答案比您要的要多...但是这个概念(即分辨率独立性及其带来的问题以及如何克服这些问题)常常是使用WPF时遇到挫败感。至少,我想将您指向新的WPF 4.0属性 UseLayoutRounding

Heh. I know my answer was a little more than what you were asking for ... but this concept (i.e. resolution independence and the resulting problems it brings and how to get over them) can often be a point of frustration when working with WPF. At the very least, I wanted to point you to the new WPF 4.0 property, UseLayoutRounding.

更新

我只需要添加,因为我一遍又一遍地看到了这个……有时 SnapsToDevicePixels UseLayoutRounding 不起作用时起作用。我希望我能指责为什么会这样,但是绝对可以先尝试UseLayoutRounding,如果那行不通,请立即尝试 SnapsToDevicePixels

I just have to add since I've seen this over and over ... sometimes SnapsToDevicePixels works when UseLayoutRounding doesn't. I wish I could put a finger on why this is the case, but definitely try UseLayoutRounding first and if that doesn't work, don't hesitate to try SnapsToDevicePixels.

那条线太尖锐,可以割伤您!

这篇关于在WPF 4.0中何时应使用SnapsToDevicePixels?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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