c# - Three ways to make Thumbnail browser... help me choose -


I have 3 ways to create a thumbnail browser, but I feel like a good way to make it each Would you recommend the route as an experienced WPF developer?

  1. The easiest IValueConverter takes the path as the input and binds for the image source.

      & lt; Image source = "{binding fullpath, converter = {StaticResource UriToBitmapConverter}, mode = -bar, IsAsync = true}" ... /> Public category UriToBitmapConverter: IValueConverter {Public Object Convert (Object Value, Type TargetType, Object Parameter, System.Globalization.CultureInfo Culture) {If (Value == Faucet) Return Null; Bitmap image img = gate image (string) value); Return img; }  

  2. .Controls.Image {Public MyImage () {this.Loaded + = New RoutedEventHandler (MyImage_Loaded); } Zero MyImage_Loaded (Object Sender, RoutedEventArgs E) {Task.Factory.StartNew ((=) gt; {var source = GetImage (mypath); this.Dispatcher.Invoke ((=) = this.Source = Source) ;}); } ...

  3. When there is a conversion in a class, where I store all the file data, and also the thumbnail

      & Lt; Image Source = "{Binding Path = Mime, Mode = One Time, ISSink = True}" /> Public class FileData: INotifyPropertyChanged {Private string fullPath; Public Bitmapsource MyImage {get {if (_myimage == null) _myimage = GetImage (full path); Return _myimage; Option 2 is the best way for me and to load each thumbnail in one thread. The Easy Way Yet none of them looks good for network drive browsing and changing folders during long image extraction, because I do not see any way to cancel the operation properly.   

    I load the image by binding path strings on Image.Source I will use WPF for Using a ItemsControl You ItemTemplate How do you want to display items, in this case you have an image with which source is fullpath type Wanted string that can set No converter is necessary.

      & amp; Lt; Items control datacontax = "{binding items}" & gt; & Lt; ItemsControl.ItemsPanel & gt; & Lt; ItemsPanelTemplate & gt; & Lt; Virtualizing StackPanel Orientation = "Horizontal" /> & Lt; / ItemsPanelTemplate & gt; & Lt; ItemsControl.ItemTemplate & gt; & Lt; DataTemplate & gt; & Lt; Image source = "{binning flowerpath}" /> & Lt; / DataTemplate & gt; & Lt; /ItemsControl.ItemTemplate> & Lt; / ItemsControl>  

    If you are just looking to load images, then I suggest that you can create a panel that can handle virtualization and use it for your item panel template As can be done. Another suggestion for this control is to load faster UserControl which will load the image in the background and use it in the DataTemplate. Both of these will improve the performance of your application.


Comments