1

I added image to Resources:

Right click on project -> Properties -> Resources.

Then set variable in Class:

var icon = Resources.BLUEJAYF4

In XAML use it like:

<Image Source="{Binding icon }" Width="150" Height="150"></Image>

But it doesn't show. How to set Resource path from code?

1 Answer 1

1

Maybe this isn't the best way to do it. But this is how I handle binding images programmatically.

You should have a property of BitmapImage like so:

    private BitmapImage photoSelected;

    public BitmapImage PhotoSelected
    {
        get { return photoSelected; }
        set { photoSelected = value; OnPropertyChanged("PhotoSelected"); }
    }

Then on the action that you desire you do this:

PhotoSelected = new BitmapImage(new Uri(@"pack://application:,,,/Images/4.png"));

Replace /Images/4.png with the path to your image starting at the solution level. For example, this is what my solution tree looks like to reach that point:

Solution Tree

Edit: I didnt think about this, but here is also the xaml I use to bind to that property.

<Image x:Name="BitMapImage" Source="{Binding PhotoSelected, Mode=TwoWay}" RenderOptions.BitmapScalingMode="HighQuality"/>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.