Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to add images from file location WPF

Tags:

c#

wpf

Am stuck to load images from my file location in WPF.

here is my xaml

<Image Grid.ColumnSpan="3" Grid.Row="11" Height="14" HorizontalAlignment="Left" Margin="57,1,0,0" Name="image1" Stretch="Fill" VerticalAlignment="Top" Width="108" />

Here is my code behind

internal int FindImages(string slugName, DirectoryInfo outputFolder)
{
    if (slugName != null)
    {
        List<string> filePathList = Directory.GetFiles(outputFolder.FullName).ToList();
        List<string> filePathList_ToBeDeleted = new List<string>();
        foreach (string filePath in filePathList)
        {                  
            if (Path.GetFileNameWithoutExtension(filePath).ToLower().Contains("_70x70"))
            {                           
                image1.Source = filePath;
            }                   
        }
        int count = 0;

        return count;
    }

My file path shows like "\\\\Server1\\Dev\\Online\\Images\\7PMa_Test3_0306_70x70.jpg"

like image 999
Usher Avatar asked Jun 03 '13 01:06

Usher


People also ask

How do I use resource image in WPF XAML?

Set your Image source like this: <Image Source={Binding {x:Static UI:Resources. Search}} /> where 'Search' is name of the resource. Save this answer.


1 Answers

Here's the catch

image1.Source = new BitmapImage(new Uri(filePath));
like image 82
Nikhil Agrawal Avatar answered Oct 13 '22 15:10

Nikhil Agrawal