c# - UWP WIndows-10 Loading images in app -


i have c# app targeting windows uwp platform. app displays images in list view. based on query made, these images can come either app's

  1. container(/assets/ folder)
  2. online source
  3. local source


when image's source either in app's container or online source can bind image source valid uri in xaml fetch image.
when image's source local, url image proprietary & use our own imge_fetch api image our servers.

my problem how specify xaml binding capable of taking either uri(when image app's container or online source) or bitmapimage(returned our image_fetch apis)


have checked post regarding ivalueconverter
i want know, if there better/easier way in uwp trying achieve.

you may create view model item class source property of type object, can assign string, uri or imagesource:

public class imageitem {     public object imagesource { get; set; } } 

in xaml, can directly bind property , benefit built-in automatic type conversion:

<listbox itemssource="{binding}">     <listbox.itemtemplate>         <datatemplate>             <image source="{binding imagesource}"/>         </datatemplate>     </listbox.itemtemplate> </listbox> 

assigning image items this:

datacontext = new imageitem[] {     new imageitem { imagesource = "ms-appx:///assets/storelogo.png" },     new imageitem { imagesource = new uri("ms-appx:///assets/square150x150logo.scale-200.png") },     new imageitem { imagesource = new bitmapimage(new uri("ms-appx:///assets/square44x44logo.scale-200.png")) }, }; 

Comments

Popular posts from this blog

scala - 'wrong top statement declaration' when using slick in IntelliJ -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

PySide and Qt Properties: Connecting signals from Python to QML -