我想在運行時使用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