我正在开发我的第一个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
嗨,是不是真的很多使用。不管怎么说,还是要谢谢你。 –