【问题标题】:Windows Mobile 7 - C# Changing image source at run timeWindows Mobile 7 - C# 在运行时更改图像源
【发布时间】:2012-05-21 06:21:28
【问题描述】:

我正在尝试在运行时更改图像的来源,以便在点击后更改图像。到目前为止,我下面的代码似乎导致图像变为空白。

BitmapImage imgSource = 
            new BitmapImage(new Uri("/PivotApp1;component/Images/halfstar.png"));
image1.Source = imgSource;

在运行时更改资源图像是否需要做一些特别的事情?我试过通过谷歌搜索,但是,到目前为止,每一个类似的情况都会导致一个空白图像。我想也许源 uri 是错误的,但我已经排除了这不是原因,因为这是加载默认图像时的 uri。

【问题讨论】:

    标签: c# windows-phone-7 runtime bitmapimage


    【解决方案1】:

    告诉URI是相对的

    BitmapImage imgSource = new BitmapImage(
              new Uri("/PivotApp1;component/Images/halfstar.png", UriKind.Relative));
    

    在分配 ImageSource 之前尝试将 source 设置为 null

    image1.Source = null;
    image1.Source = imgSource;
    

    【讨论】:

    • 谢谢,成功了。我想它需要加入 UriKind.Relative。
    • 谢谢你。很高兴能帮到你。
    猜你喜欢
    • 2011-01-26
    • 1970-01-01
    • 2010-09-28
    • 1970-01-01
    • 1970-01-01
    • 2011-09-09
    • 2012-11-02
    • 2010-10-30
    • 2018-12-07
    相关资源
    最近更新 更多