Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/299.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 单击按钮时更新ImageSource_C#_Xaml - Fatal编程技术网

C# 单击按钮时更新ImageSource

C# 单击按钮时更新ImageSource,c#,xaml,C#,Xaml,当我加载并填充我的列表框时,我会检查bool值是true还是false,并根据该bool绑定当前图像(liked.png或notliked.png) 列表框中的按钮: <Button Click="LikePost"> <Button.Background> <ImageBrush Stretch="Uniform" ImageSource="{Binding imagesource}"/> </Button.Backgr

当我加载并填充我的
列表框时,我会检查
bool
值是
true
还是
false
,并根据该
bool
绑定当前图像(liked.png或notliked.png)

列表框中的按钮:

<Button Click="LikePost">
    <Button.Background>
        <ImageBrush Stretch="Uniform" ImageSource="{Binding imagesource}"/>
    </Button.Background>
</Button>
<Image Source="liked.png" Visibility="collapsed"/>
<Image Source="notliked.png" Visibility="collapsed"/>
在LikePost函数中,我检查帖子是否受欢迎,并相应地更改类中的imagesource。但是图像不会改变?

您可以试试这个

如果您的silverlight应用程序位于/ClientBin文件夹下,则url应与ClientBin相对。因此,如果您的图像位于web应用程序的正下方,您可以尝试新的Uri(“../path.png”,UriKind.Relative)


您还可以使用fiddler或chrome developer工具(网络选项卡)捕获图像请求,这将显示您请求的url。

您有权访问此文件吗?为什么
Absolute
而不是
RelativeOrAbsolute
文件在我的根目录中。当我使用“绝对”时,我得到了“System.UriFormatException”。
UriKind.RelativeOrAbsolute
很抱歉没有正确阅读您的答案。当我使用RelativeOrAbsolute时,没有显示图像。
public class Item : INotifyPropertyChanged
{
    public string value1 { get; set; }

    public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;
    private System.Windows.Media.ImageSource _imagesource;
    public System.Windows.Media.ImageSource imagesource
    {
        get { return _imagesource; }
        set
        {
            if (_imagesource == value) return;
            _imagesource = value;
            NotifyLikeImageChanged("like");
        }
    }
    private void NotifyLikeImageChanged(string propertyName)
    {
        System.ComponentModel.PropertyChangedEventHandler handler = PropertyChanged;
        if (PropertyChanged != null)
            PropertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName));
    }
}