我在windows phone的是新的,圖像的高度和寬度的問題7
現在這樣只是想顯示堆棧面板的圖像的樣本。
我想顯示圖像的實際高度和寬度。但實際的高度和寬度返回0.
實際上,圖像的高度爲360px,寬度爲480px。
我在下面發佈我的代碼。請幫助。
謝謝。
MaingPage.xaml
<Grid x:Name="LayoutRoot" Background="Transparent">
<StackPanel Name="imagePanel" ></StackPanel>
</Grid>
MainPage.xaml.cs中
namespace ImageResizing
{
public partial class MainPage : PhoneApplicationPage
{
Image myImage;
BitmapImage bit;
// Constructor
public MainPage()
{
InitializeComponent();
myImage = new Image();
Uri uri = new Uri("Penguins.jpg", UriKind.Relative);
bit = new BitmapImage(uri);
myImage.Source = bit;
myImage.Width = myImage.ActualWidth; // Returns 0
myImage.Height = myImage.ActualHeight; // Returns 0
myImage.Width = bit.PixelWidth; // Also tried this. It returns 0 too
myImage.Height = bit.PixelHeight; // Also tried this. It returns 0 too
myImage.Stretch = Stretch.Fill;
imagePanel.Children.Add(myImage);
}
}
}
我重排的代碼爲u說。但高度和寬度仍然返回0.只需檢查上面的編輯代碼。 – Arun 2012-02-25 05:48:53
這個網站:http://www.i-programmer.info/programming/wpf-workings/520-bitmapimage-and-local-files-.html?start=1可能有一些與你所看到的相關的更多細節? – 2012-02-25 06:08:31