画布背景的装订尺寸

发布于 2024-10-19 17:40:37 字数 242 浏览 1 评论 0原文

我有一个画布,需要使用各种尺寸的自定义图像的图形背景,但我想将背景图像的高度和宽度绑定到某处的某些属性。现在我有一个图像显示为背景,但其大小是固定的。事实证明,图像和图像画笔的宽度和高度属性是只读的。有没有办法绑定宽度和高度?

ps 我尝试过视口,但它使用矩形对象,并且它的宽度和高度不是依赖属性。然后我尝试使用视口的一个图块并将其放入一个矩形中,然后我可以调整矩形的大小以实现我想要的效果,但我不知道如何将矩形作为画布的背景。有什么想法吗?提前致谢。

I have a canvas that needs a graphical background using custom images of various sizes, but I want to bind the height and width of the background image to some properties somewhere. right now I have an image displaying as background but its size is fixed. It turns out that the width and height property of the image and of the imagebrush is readonly. Is there anyway to bind the width and height?

p.s I have tried viewport, but it uses a rect object and its width and height are not dependency properties. Then I tried to use one tile of the viewport and put it in a rectangle then I can resize the rectangle to achieve what I want but I cannot figure out how to put a rectangle as the canvas's background. Any Ideas? Thanks in advance.

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

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

发布评论

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

评论(2

久光 2024-10-26 17:40:37

一种简单的方法是使用 VisualBrush 作为 Canvas 的背景。将 Stretch 设置为 None,然后在 Visual 中绑定 Image 的宽度和高度

<Canvas ...>
    <Canvas.Background>
        <VisualBrush Stretch="None">
            <VisualBrush.Visual>
                <Image Source="SomeSource"
                       Stretch="Fill"
                       Width="{Binding ...}"
                       Height="{Binding ...}"/>
            </VisualBrush.Visual>
        </VisualBrush>
    </Canvas.Background>
    <!--...-->
</Canvas>

An easy way is to use a VisualBrush as the Background for the Canvas. Set Stretch to None and then bind the Width and Height of the Image in the Visual

<Canvas ...>
    <Canvas.Background>
        <VisualBrush Stretch="None">
            <VisualBrush.Visual>
                <Image Source="SomeSource"
                       Stretch="Fill"
                       Width="{Binding ...}"
                       Height="{Binding ...}"/>
            </VisualBrush.Visual>
        </VisualBrush>
    </Canvas.Background>
    <!--...-->
</Canvas>
彻夜缠绵 2024-10-26 17:40:37

不能说我设法完全遵循您想要做的事情,但您可以使用 VisualBrush 将矩形作为画布的背景。

我有点确定你正在做的事情可以很容易解决 - 但我无法真正理解你想要做什么。

Can't say that i managed to follow what you're trying to do exactly, but you can use VisualBrush to put the Rectangle as the background of the canvas.

I'm somewhat sure that what you're doing can be solved easily - but I couldn't really understand what it is you're trying to do.

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