c# - WPF Binding to converter for an Image (Bitmap) not showing -


i having issues image not showing in wpf control using converter create image local directory. direction on doing wrong appreciated.

xaml

<usercontrol x:class="coms.views.imagedetailview"          xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"          xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"          xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"           xmlns:d="http://schemas.microsoft.com/expression/blend/2008"           xmlns:c="clr-namespace:coms.converter"          mc:ignorable="d"           d:designheight="100" d:designwidth="300" background="wheat"> <control.resources>     <c:imagedetailconverter x:key="converter" /> </control.resources> <listbox itemssource="{binding iclist}" scrollviewer.horizontalscrollbarvisibility="disabled" scrollviewer.verticalscrollbarvisibility="auto">     <listbox.itemtemplate>         <datatemplate>             <grid>                 <grid.columndefinitions>                     <columndefinition width="100"/>                     <columndefinition width="200"/>                 </grid.columndefinitions>                 <image name="imgbox" width="auto" height="auto" grid.column="0" source="{binding converter={staticresource converter}}" />                 <textblock name="txtblock2" grid.column="1" text="{binding coordinates}"/>             </grid>         </datatemplate>     </listbox.itemtemplate> </listbox> 

class

public class imagedetail {     public string filename { get; set; }     public string coordinates { get; set; } } 

converter

public class imagedetailconverter : ivalueconverter {     public object convert(object value, type targettype, object parameter, system.globalization.cultureinfo culture)     {         iruntimeconfigurations configs = servicelocator.current.getinstance<iruntimeconfigurations>();         return new bitmap(image.fromfile(path.combine(configs.rootimagepath, ((iimagedetail)value).filename)));     } } 

your converter returns system.drawing.bitmap, winforms, not wpf.

it should return wpf imagesource (e.g. bitmapimage) instead:

public object convert(     object value, type targettype, object parameter, cultureinfo culture) {     var imagedetail = (imagedetail)value;     var configs = servicelocator.current.getinstance<iruntimeconfigurations>();     var path = path.combine(configs.rootimagepath, imagedetail.filename);     var uri = new uri(path, urikind.relativeorabsolute);      return new bitmapimage(uri); } 

note wpf provides built-in type conversion uri , string (containing valid uri) imagesource, converter return uri or path value.


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -