c# - Cannot implicitly convert type 'string' to 'Windows.UI.Xaml.Media.Imaging.BitmapImage -
i trying show image stored in local directory inside xaml design.
i have path local image.
imagepage.xaml
<scrollviewer> <listview x:name="viewimage" selectionmode="none" isactiveview="true"> <listview.itemspanel> <itemspaneltemplate> <wrapgrid orientation="horizontal" maximumrowsorcolumns="1" /> </itemspaneltemplate> </listview.itemspanel> <listview.itemtemplate> <datatemplate> <grid x:name="imggrid"> <grid.rowdefinitions> <rowdefinition height="auto" /> <rowdefinition height="auto" /> </grid.rowdefinitions> <stackpanel> <grid height="50" width="50"> <grid margin="2" background="red"> <image source="{binding imgart}" stretch="uniformtofill" height="40" width="40"/> </grid> </grid> </stackpanel> </grid> </datatemplate> </listview.itemtemplate> </listview> </scrollviewer>
imagepage.xaml.cs
string strimgpath = "ms-appx:///images/music/localimg.png"; public string imgpath { { return strimgpath; } } imageclaz obj = new imageclaz(); obj.imgart = imgpath;
imageclaz()
public class imageclaz { public string imgart { get; set; } }
you should use windows.ui.xaml.media.imaging.bitmapimage if targeting winrt app.
just change imgart froms string bitmapimage
public class imageclaz { public bitmapimage imgart { get; set; } }
and set image this,
string strimgpath = "ms-appx:///images/music/localimg.png"; imageclaz obj = new imageclaz(); obj.imgart = new bitmapimage(new uri(strimgpath, urikind.absolute));
Comments
Post a Comment