将画布放入Silverlight中的Viewbox与图像 [英] Putting Canvas Inside Viewbox in Silverlight With Image

查看:108
本文介绍了将画布放入Silverlight中的Viewbox与图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

全部,

我正在尝试制作我正在以合理方式调整大小的Silverlight应用程序。为此,我想我会使用动态网格。在网格的中心,我需要将一个图像放在画布中,因为我会动态地将对象放在它上面。理想情况下,当用户使浏览器窗口变大时,中间列将能够调整大小并变大,从而增大图像。

I'm trying to make the silverlight app I'm making resize in a reasonable manner. To do this, I thought I would use a dynamic grid. In the center of the grid I need to put an image inside of a canvas because I will dynamically be positioning objects on top of it. Ideally, as the user makes the browser window larger, the center column would be able to resize and grow larger, thereby growing the image.

这是我得到的:

<Viewbox Grid.Row="0" Grid.Column="1">
    <Canvas x:Name="cvsCenterPane">
        <Image x:Name="imgFormImage" MouseLeftButtonDown="imgFormImage_MouseLeftButtonDown" 
                 MouseLeftButtonUp="imgFormImage_MouseLeftButtonUp" MouseMove="imgFormImage_MouseMove" />
    </Canvas>
</Viewbox>

在后面的代码中,我然后设置了图像源。

In the code behind, I then set the image source.

这是我的网格定义:

<Grid x:Name="LayoutRoot" Background="DarkCyan" ShowGridLines="True">
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="300" />
        <ColumnDefinition Width="*" />
        <ColumnDefinition Width="300" />
    </Grid.ColumnDefinitions>
    <Grid.RowDefinitions>
        <RowDefinition Height="*" />
        <RowDefinition Height="100" />
    </Grid.RowDefinitions>

我认为在构建Viewbox期间必定会出现某种未处理的异常,因为图像确实存在根本不显示。我在这做错了什么?我采取了错误的方法吗?

I think there must be some sort of unhandled exception occurring during the construction of the Viewbox because the image does not display at all. What am I doing wrong here? Am I taking the wrong approach?

推荐答案

没有例外,画布没有任何设定的尺寸,这是一个要求当你想使用ViewBox时。

There is no exception, the canvas just does not have any set dimensions which is a requirement when you want to use a ViewBox.

我不会使用画布,你可以坚持使用网格,因为你可以在一个单元格中放置多个控件如果你需要移动周围的物体,可以使用 保证金 TranslateTransform RenderTransform 财产。

I for one would not use a canvas, you can stick with the grid since you can place more than one control in a cell and if you need to move the objects around you can use the Margin or a TranslateTransform in the RenderTransform property.

这篇关于将画布放入Silverlight中的Viewbox与图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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