在 Silverlight 中缩放后形状之间的间隙

发布于 2024-10-26 19:24:57 字数 220 浏览 11 评论 0原文

创建一个 400 x 400 画布。在其中放置一个 200 x 400 的蓝色矩形。放置另一个蓝色矩形,大小相同,Canvas.Left = 200。将其包裹在 Viewbox 中并缩放视图框。在某些分辨率下,您会发现矩形之间出现白色柱,尽管它们应该是齐平的。

我怎样才能避免这种情况?到目前为止我发现的唯一方法是将右侧矩形左侧的画布设置为略小于 200,例如 199 - 但即使这样也会在某些比例下显示伪影。

Create a 400 x 400 Canvas. Put a Blue rectangle that is 200 x 400 in it. Put another Blue rectangle, same size, with Canvas.Left = 200. Wrap this in a Viewbox and scale the view box. At certain resolutions, you will find a white column appears between the rectangles despite the fact they are supposed to be flush.

How can I avoid this? The only way I've found so far is to set the canvas left of the right rectangle to slightly less than 200, like 199 - but even that shows artifacts at certain scales.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

枫林﹌晚霞¤ 2024-11-02 19:24:57

ViewBox 中的 ScaleTransform 给您带来了麻烦。文本的像素捕捉将在 Silverlight 5 中提供,但我不确定所有 UI 元素。

使用 Dave Reyea 的 Pixel Snapper 可以帮助您解决这个问题:

<UserControl x:Class="SO_Viewbox.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    d:DesignHeight="300" d:DesignWidth="400"
              xmlns:local="clr-namespace:SO_Viewbox">

    <Viewbox>
        <Canvas Width="400" Height="400" Background="Yellow">
            <local:Snapper Snap="TopLeft">
                <Rectangle Width="200" Height="400" Fill="Blue" />
            </local:Snapper>
            <local:Snapper Canvas.Left="200" Snap="TopLeft">
                <Rectangle  Width="200" Height="400" Fill="Blue" />
            </local:Snapper>
        </Canvas>
    </Viewbox>
</UserControl>

他还展示了如何将其实现为 依赖属性。如果您可以修改 Viewbox 来纠正该问题,那就太好了,但在我看来,这不能简单地通过修改 Viewbox 的变换来解决 - 相反,像素捕捉必须应用于该视图的每个后代元素。视图框。

The ScaleTransform in ViewBox is giving you trouble. Pixel snapping for text will be delivered in Silverlight 5, but I'm not sure about all UI elements.

Using Dave Reyea's Pixel Snapper can help you get around this:

<UserControl x:Class="SO_Viewbox.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    d:DesignHeight="300" d:DesignWidth="400"
              xmlns:local="clr-namespace:SO_Viewbox">

    <Viewbox>
        <Canvas Width="400" Height="400" Background="Yellow">
            <local:Snapper Snap="TopLeft">
                <Rectangle Width="200" Height="400" Fill="Blue" />
            </local:Snapper>
            <local:Snapper Canvas.Left="200" Snap="TopLeft">
                <Rectangle  Width="200" Height="400" Fill="Blue" />
            </local:Snapper>
        </Canvas>
    </Viewbox>
</UserControl>

He also shows how to implement it as a dependency property. It would be nice if you could modify Viewbox to correct the issue, but it seems to me that this can't simply be solved by modifying the Viewbox's transform -- that instead, pixel snapping must be applied to each of the decendant elements of the Viewbox.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文