Logic
In WPF applications, for backend C# language is used which is an Object Oriented Programming Language introduced by Microsoft on .NET Framework. It is used to develop Mobile Applications, Desktop Applications, Web Applications, Games, Database Applications and much more.
In C#, we have to import the required packages from .NET framework in our project by 'using' statement. You can find a lots of using statements at the beginning of the code. Visual Studio Professional 2019 has a feature that can automatically suggest you the package which is missing in your project or you require to execute the project.
As you are creating a WPF application, the class of the MainWindow will be inherited from Window(which is mentioned in xaml) and it has 1 inbuilt constructor that contains InitializeComponent() method which initializes the UI (xaml code) of the project.
I have created a class named MyImageClass which has a string and a ImageSource image. So all of our images that are fetched from the selected folder are stored in this variables in this class.
I have created ObservableCollection<MyImageClass> that takes all the images with it's names from MyImageClass and stores it. You can find FillImages() method works on fetching images from ObservableCollection<>, converts the image into BitmapImage and add it to the collection. Here, FolderBrowserDialog() is used to select the folder for which user want to display images. But it is component of Windows Forms and not WPF. WPF doesn't have it's inbuilt FolderBrowserDialog() through which user select images. So here, we need to give reference to the Windows.Forms assembly to use it's components.
You will find keyboard and mouse events which we have created on frontend side using xaml. So we have to write it's logic here in C#. In txtsearch_keydown, I have written that ''if(e.Key==Key.Enter)'', which means if user presses Enter key then only the keydown event will performed. The logic to search image is written in SearchText() method. I had used concept of DependencyObject in MouseDoubleClick event which helped me to differentiate the object on which the doubleclick performed. If the doubleclick is performed on any image of the window, the Process.Start() method will opens that image in your system. But if the doubleclick is not performed on image, it will perform search function as SearchText() method is called there.
At the end of project, I had created a class TruncateConverter which is inherited from the interface IValueConverter. We had binded it in xaml code to display the title of the image. It will compare the characters in title with the maximum limit, and if it exceeds the limit then it will convert the extra characters into ''...'' .
Comments
Post a Comment