小编Sam*_*son的帖子

在创建UWP应用程序时,如何使用C#更改image.source?

我正在开发我的第一个Windows 10 UWP应用程序.我有一张图片.这是它的XAML代码:

<Image x:Name="image" 
               HorizontalAlignment="Left"
               Height="50" 
               Margin="280,0,0,25" 
               VerticalAlignment="Bottom" 
               Width="50" 
               Source="Assets/Five.png"/>
Run Code Online (Sandbox Code Playgroud)

我试图用这段代码改变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 …
Run Code Online (Sandbox Code Playgroud)

c# xaml win-universal-app

8
推荐指数
2
解决办法
9664
查看次数

标签 统计

c# ×1

win-universal-app ×1

xaml ×1