【发布时间】:2015-02-12 05:20:45
【问题描述】:
我想在运行时使用 C# 更改图像源。我试过这个。
在 MainPage.xaml 中,
<Image x:Name="myImage" HorizontalAlignment="Left"
Height="125"
Margin="86,76,0,0"
VerticalAlignment="Top"
Width="220" />
<Button Content="Button"
HorizontalAlignment="Left"
Margin="134,230,0,0"
VerticalAlignment="Top"
Click="Button_Click"/>
在 MainPage.xaml.cs 中
private void Button_Click(object sender, RoutedEventArgs e)
{
myImage.Source = new BitmapImage(new Uri("/Assets/WorldCupFlags/Sri_Lanka.png", UriKind.Relative));
}
它没有显示编译时错误,但是当我运行它并单击按钮时,它显示异常。它说“在 mscorlib.ni.dll 中发生了 'System.ArgumentException' 类型的异常,但未在用户代码中处理。”
【问题讨论】:
-
您是否在 Windows Phone Blank App 中打开过? @彼得托尔
-
对不起,没有看到标题中的“RT”(我只是看了标签)。解决方案如下。
标签: c# xaml windows-phone