Click here to Skip to main content
15,887,214 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
C#
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
C#
<Image Width="24" Height="24" HorizontalAlignment="Left" VerticalAlignment="Top">
 <Image.Source>
  <BitmapImage UriSource="{Binding ImageStatusPath}"/>
 </Image.Source>
</Image>
Posted
Updated 5-Apr-16 17:03pm
v3
Comments
Sergey Alexandrovich Kryukov 5-Apr-16 13:47pm    
You don't even try to refresh anything, merely modify a string member, which is not even a property, so what could you possibly expect? You can, say, modify the image source, it will trigger the invalidation.
—SA

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[^]
 
Share this answer
 
v2
The UI doesn´t recognize the changes of the Imagestatuspath because of following reasons:

1 UI elements only can regcognize changes of properties in bindings when their class implement INotifyPropertyChanged

2 When you implement INotifyPropertyChanged you have to use a setter for the property following the INotifyPropertyChanged pattern to propagate a change

I know i am late but maybe my answer helps some people with the same issue.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900