App.structure.Add(new School() { id = Id, Number = number, Type = type, Info = info, Sour = sour }); jsonArray_Item = jsonArray_Item.Next; } SchoolList.Items.Clear(); load.Visibility = Visibility.Collapsed; SchoolList.ItemsSource = App.structure; 

Here I fill the list , and then I list the ListView on this list. "Sour" is a link to an image (in which only the last digits change). The problem is that not all links have an image, as in the case of no image from the server, to display an alternative?

On the account of the converter, my field is not empty ...

 string sour = "http://www.schoolapp.ru/img_schools/" + number + ".jpg"; 

It is necessary to check whether there is an image by reference ... Either somehow modify the code.

  • Look at the site, it was already. With MultiBinding, for example. - VladD
  • Is it possible to make Sour property and perform a check in a hetero? - Mirdin

1 answer 1

You can make a converter that will check if the url field is empty, then give some hard-coded url.

for example, if you use a binding:

 <Image Source="{Binding ImageUrl, Converter={StaticResource CheckForNullConverter}}"/> 

here the converter must be specified in the resources

 xmlns:converters="using:App.Converters" <converters:CheckForNullConverter x:Key="MyConverter"/> 

and it should be implemented

 public class CheckForNullConverter : IValueConverter { public object Convert(object value, ...) { return value==null?"defaultImagePath":value; } } 
  • Try to write more detailed answers. Explain what is the basis of your statement? - Nicolas Chabanovsky ♦