我正在开发图片查看器应用程序,我想为其添加新功能。
到目前为止,我已经在 XAML 中固定了 Image 控件的大小
Height="422" Width="444"
,但我想使用页面上所有可能的空间,它是 Width="447" Height="585"
<StackPanel Height="422" Width="444">
<Image Height="414" HorizontalAlignment="Center" Margin="9,6,0,0" Name="image2" Stretch="Uniform" VerticalAlignment="Center" Width="441" />
</StackPanel>
代码所以
var stream = new IsolatedStorageFileStream(path, FileMode.Open, _file);
var image = new BitmapImage();
image.SetSource(stream);
stream.Close();
if (image1 != null) image1.Source = image;
,我的问题是:
- 如何从后面的代码设置图像控件的大小,以便图片适合
Width="447" Height="585"
尺寸,我有纵向和横向的图片?
- 我需要纵向和横向方向支持,因此当方向更改时,我希望图片适合新尺寸
Width="585" Height="447"
,我该如何管理? (我想如果我能找到第一个问题的解决方案,那么我只需要正确的事件来处理这个问题)与此类似(http://stackoverflow.com/questions/6857142/handling-size-of-image-after- orientation-change-wp7),但我需要看一些代码才能理解。
请发布一些代码或教程链接,以防止“经典”对话框,其中一个人现在如何做并认为它很简单,而其他人现在知道它是如何工作的。
I am developing picture viewer application and I want to add new function to it.
Till this time, I have fixed size of Image control in the XAML
Height="422" Width="444"
,but I want to use all possible space on the page and it is Width="447" Height="585"
<StackPanel Height="422" Width="444">
<Image Height="414" HorizontalAlignment="Center" Margin="9,6,0,0" Name="image2" Stretch="Uniform" VerticalAlignment="Center" Width="441" />
</StackPanel>
Code behind
var stream = new IsolatedStorageFileStream(path, FileMode.Open, _file);
var image = new BitmapImage();
image.SetSource(stream);
stream.Close();
if (image1 != null) image1.Source = image;
So, my question is:
- How I can set the size of the Image control from the code behind, so the picture will fit to the
Width="447" Height="585"
size, I have both portrait and landscape oriented pictures?
- I need to have portrait and landscape orientation support, so when orientation is change I would like to picture fit to new size
Width="585" Height="447"
, how I can manage that? (I guess if I will find solution to the first, than only think I need is right event to handle this) Similar to this (http://stackoverflow.com/questions/6857142/handling-size-of-image-after-orientation-change-wp7), but I need to see some code t in order to understand.
Please, post some code or link to the tutorial, in order to prevent “classic” dialog where one person now how to do it and think it is simple and other person have now idea how it work.
发布评论
评论(3)
您可以通过图像控件的 Width 和 Height 属性直接更改其大小。
如果您想正确地适应图像控件中的图片,则可以使用属性 Stretch
来处理方向更改,处理页面的
OrientationChanged
事件并在其中进行图像操作You can directly change the size of image control through it's Width and Height properties.
If you want to fit in your picture in the Image Control properly then you can use property Stretch
For handling the orientation change handle the
OrientationChanged
event of your page and do the image manipulation inside it试试这个,
当改变方向时会引发以下事件。
最初的方向是PortraitUp,然后
我的英语很差,如果有任何错误不介意。
Try this one,
when change the orientation then the following event is reaised.
initially orientation is PortraitUp then
I poor in english, if any mistakes dont mind.
谢谢你们的回答,我是这样做的:我制作了
和
Name="image1" Stretch="UniformToFill"/ >
因此,Silverlight 将为我完成所有工作。Thanks for your answers guys, I did it this way: I have made
<Image Height="Auto" Width="Auto"
andName="image1" Stretch="UniformToFill"/>
So, the Silverlight will do all job for me.