W
W
wolfak2015-05-28 10:27:40
WPF
wolfak, 2015-05-28 10:27:40

How to add images folder to resources in WPF?

Good afternoon. Asked another question.
At the root of the application there is a folder uploads/2015/ with images (which can be added or deleted). How can I add an entire folder to resources in order to use images in an application?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Artyom, 2015-05-28
@wolfak

To use images in your application, you don't have to add them to resources, especially if they will be added and removed. Suppose your form has an Image control named Pict, then to display some picture in it, you can use the following example:
using System;
using System.Windows;
using System.Windows.Media.Imaging;
using System.Reflection;
using FilePath=System.IO.Path;
namespace WpfApplication1
{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
var directory=FilePath.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
Pict.Source = new BitmapImage(new Uri(FilePath.Combine(directory, "uploads/2015/logo.jpg")));
}
}
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question