我想在运行时使用C#更改图像源。我试过这个。在C#中为windows phone 8.1更改图像源RT
在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的应用空白打开? @Peter Torr – Tanvir 2015-02-12 05:48:07
对不起,没有看到标题中的“RT”(我只是看着标签)。以下解决方案 – 2015-02-12 05:58:20