如何在表单调整大小上调整图像大小 [英] How to resize image on form resize

查看:95
本文介绍了如何在表单调整大小上调整图像大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在运行时调整表单大小时,图像不会调整大小. 代码段如下:

 

< x :

xmlns

xmlns x

标题 =" 380" 宽度 ="610" ResizeMode ="" CanResize">

网格 >

DockPanel x : 名称

ScrollViewer Horizo​​ntalScrollBarVisibility =" Visible" 名称 =" scrollViewer" VerticalScrollBarVisibility =可见" ="1" DockPanel.Dock =" Top" >

图片 来源 ="/TestWA1; component/Img/ASCE98MapNew. bmp" 高度 ="30959" =""55723" 边距 ="5,5,5,5" =" AP_imgMap" 拉伸 =" Fill" VerticalAlignment =" Stretch" Horizo​​ntalAlignment =" Stretch" >

Image.LayoutTransform >

TransformGroup >

ScaleTransform ScaleX ="0.01" ScaleY =" 0.01"/>

ScaleTransform >

ScaleTransform.ScaleX >

绑定 ElementName =" sldZoom" 路径 =" Value" 模式 ="OneWay"/>

ScaleTransform.ScaleX >

ScaleTransform.ScaleY >

绑定 ElementName =" sldZoom" 路径 =" Value" 模式 =" OneWay"/>

ScaleTransform.ScaleY >

</ScaleTransform>

</TransformGroup>

</Image.LayoutTransform>

</Image>

</ScrollViewer>

</DockPanel>

</Grid>

</Window>

Please tell me the appropraite solution to resize the image on form resize.

解决方案

Hi San S,

If you set a fix size to your Image control like: "Height="30959" Width="55723" " and then it will not be resized, if you want to set dynamica size to your image, you could Bind your Image size to your Window,

Height="{Binding ElementName=myWindow, Path=ActualHeight}"

if you need return the Height after calculate, you could add a Conveter to your Binding.

 

最好的问候


When I resize the form on runtime, the image is not resize. The code snippet is below:

 

<Window x:Class="TestWA1.Image1"

xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

Title="Image1" Height="380" Width="610" ResizeMode="CanResize">

<Grid>

<DockPanel x:Name="LayoutRoot" >

<ScrollViewer HorizontalScrollBarVisibility="Visible" Name="scrollViewer" VerticalScrollBarVisibility="Visible" Opacity="1" DockPanel.Dock="Top" >

<Image Source="/TestWA1;component/Img/ASCE98MapNew.bmp" Height="30959" Width="55723" Margin="5,5,5,5" Name="AP_imgMap" Stretch="Fill" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" >

<Image.LayoutTransform>

<TransformGroup>

<ScaleTransform ScaleX="0.01" ScaleY="0.01"/>

<ScaleTransform>

<ScaleTransform.ScaleX>

<Binding ElementName="sldZoom" Path="Value" Mode="OneWay"/>

</ScaleTransform.ScaleX>

<ScaleTransform.ScaleY>

<Binding ElementName="sldZoom" Path="Value" Mode="OneWay"/>

</ScaleTransform.ScaleY>

</ScaleTransform>

</TransformGroup>

</Image.LayoutTransform>

</Image>

</ScrollViewer>

</DockPanel>

</Grid>

</Window>

Please tell me the appropraite solution to resize the image on form resize.

解决方案

Hi San S,

If you set a fix size to your Image control like: "Height="30959" Width="55723" " and then it will not be resized, if you want to set dynamica size to your image, you could Bind your Image size to your Window,

Height="{Binding ElementName=myWindow, Path=ActualHeight}"

if you need return the Height after calculate, you could add a Conveter to your Binding.

 

Best regards,


这篇关于如何在表单调整大小上调整图像大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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