Wpf在更改URI源时刷新图像 [英] Wpf refresh the image when the URI source is changed
本文介绍了Wpf在更改URI源时刷新图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我希望在路径更改时更新图像
通过我的测试,当我调用SetStatus时路径改变时图像不会更新。
我尝试过:
plugin.cs
I want to update the image when the path is changed
With my test, The image is not updated when the path is changed when I call SetStatus.
What I have tried:
plugin.cs
public enum StatusType
{
Start, Pause, Stop
}
public class Plugin
{
private StatusType status_;
private String imageStatusPath_;
public Plugin()
{
SetStatus(StatusType.Stop);
}
public void SetStatus(StatusType status)
{
status_ = status;
if (status == StatusType.Stop)
imageStatusPath_ = "Resources/Stop_24.png";
if (status == StatusType.Pause)
imageStatusPath_ = "Resources/Pause_24.png";
if (status == StatusType.Start)
imageStatusPath_ = "Resources/Play_24.png";
}
public String ImageStatusPath
{
get { return imageStatusPath_; }
}
Mainview.xaml
Mainview.xaml
<Image Width="24" Height="24" HorizontalAlignment="Left" VerticalAlignment="Top">
<Image.Source>
<BitmapImage UriSource="{Binding ImageStatusPath}"/>
</Image.Source>
</Image>
推荐答案
您应该使用数据绑定,这是WPF的一部分
在您尝试使用图像之前先学习基本知识
WPF中的数据绑定C# - YouTube [ ^ ]
WPF数据绑定 - 第1部分 [ ^ ]
You should use databinding which is part of WPF
Learn the basic first before you try the image one
Data Binding in WPF C# - YouTube[^]
WPF Data Binding - Part 1[^]
这篇关于Wpf在更改URI源时刷新图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文