我正在開發我的第一個Windows 10 UWP應用程序。我有一個形象。這是它的XAML代碼:如何在創建UWP應用程序時使用C#更改image.source?
<Image x:Name="image"
HorizontalAlignment="Left"
Height="50"
Margin="280,0,0,25"
VerticalAlignment="Bottom"
Width="50"
Source="Assets/Five.png"/>
和IM試圖改變image.source與此代碼:
private void slider_ValueChanged(object sender, RangeBaseValueChangedEventArgs e)
{
BitmapImage One = new BitmapImage(new Uri(@"Assets/One.png"));
BitmapImage Two = new BitmapImage(new Uri(@"Assets/Two.png"));
BitmapImage Three = new BitmapImage(new Uri(@"Assets/Three.png"));
BitmapImage Four = new BitmapImage(new Uri(@"Assets/Four.png"));
BitmapImage Five = new BitmapImage(new Uri(@"Assets/Five.png"));
if (slider.Value == 1)
{
image.Source = One;
}
else if (slider.Value == 2)
{
image.Source = Two;
}
else if (slider.Value == 3)
{
image.Source = Three;
}
else if (slider.Value == 4)
{
image.Source = Four;
}
else if (slider.Value == 5)
{
image.Source = Five;
}
}
但是,當我編譯代碼我得到這個錯誤指向的變量聲明:
UriFormatException是由用戶代碼未處理
嗨,感謝您的幫助。但是這導致ArgumentsException被用戶代碼處理。有任何想法嗎?謝謝 –
看看這個類似的問題:[鏈接](http://stackoverflow.com/questions/32314799/uwp-image-uri-in-application-folder) – RobertoB
嗨,是不是真的很多使用。不管怎麼說,還是要謝謝你。 –