【问题标题】:Image not displaying in Windows Phone 8 App图像未显示在 Windows Phone 8 应用程序中
【发布时间】:2013-11-15 02:31:12
【问题描述】:

我有一个 C#/XAML Windows Phone 8 应用程序。在其中,我试图在屏幕顶部显示图像;但是,当我这样做时,它不会出现。

这是我的图片:

<Image Grid.Row ="1" Grid.RowSpan="4" Grid.Column ="1"
       Width ="150" Height ="100"
       Visibility ="Collapsed" x : Name="MyImage">
     <Image.RenderTransform>
          <ScaleTransform CenterX ="75" CenterY="50">
          </ScaleTransform>
     </Image.RenderTransform>
</Image>        

这是动画的一部分(这里是故事板):

<DoubleAnimation Storyboard.TargetName ="MyImage"
                 Storyboard.TargetProperty="(UIElement.RenderTransform).(ScaleTransform.ScaleX)"
                 From ="0" To ="1" Duration="0:0:0.2"/>
<DoubleAnimation Storyboard.TargetName ="MyImage"
                 Storyboard.TargetProperty="(UIElement.RenderTransform).(ScaleTransform.ScaleY)"
                 From ="0" To ="1" Duration="0:0:0.2"/>

然后我像这样触发动画:

BitmapImage newImage = new BitmapImage ();
newImage.UriSource = new Uri( "ms-appx:///Assets/MyImage.png" ); // Can change
MyImage.Source = newImage;
MyImage.Visibility = Visibility .Visible;

Storyboard sbExpand = (Storyboard )this.Resources[storyboardName];
sbExpand.Completed += sbExpand_Completed;
sbExpand.Begin();

我知道这行得通,因为如果我用按钮替换图像,它会达到我的预期。为什么图像不显示?在这种情况下,图像甚至是正确的控件吗?

【问题讨论】:

  • 您确定此图片存在吗? VS的输出是什么?您可以静态设置此图像(来自 XAML)只是为了检查它是否在正常情况下显示?
  • 当你说它做你所期望的......它到底是什么?
  • @PiotrJustyna 是的,它在空白表单上显示良好,图像设置为始终复制并标记为内容。我的猜测是它出现在背景中。
  • 我期望控件出现并变大(根据动画)
  • 即使您直接在 XAML 中为您的“MyImage”指定“源”(不是在空白表单上),它是否也会出现?当您在此行设置断点时,您可以在“newImage”对象中看到什么:MyImage.Visibility = Visibility .Visible;?

标签: c# xaml windows-phone-8


【解决方案1】:

您不能在 Windows Phone 8 上为图像源使用 URI 方案 ms-appx,它仅适用于 Windows 8 项目。
你可以在这里查看我的博客文章,如何使用 Uri 正确链接资源/隔离存储中的图像:

Image path databinding in WP8 and Windows 8 apps

【讨论】:

  • 谢谢。完全不清楚 MS 文档是否属于这种情况。对于之后的人来说,似乎对我有用的 WP8 方式是:new uri("//Assets/MyImage.png")
猜你喜欢
  • 1970-01-01
  • 2023-03-03
  • 2014-12-28
  • 1970-01-01
  • 1970-01-01
  • 2023-03-16
  • 2023-04-10
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多