Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to handle Empty Uri's for Path Binding to an Image Source

Tags:

c#

mvvm

wpf

how can I initialize an Uri object in an empty state.

First thought would be to do something like this

//does not work
Uri myUri = Uri.Empty

This one does also not work

Uri myUri = new Uri(string.Empty)

The reason is I store my image path in the db and in case there is no image defined I have a blank database record.

I know that there are ways to handle this with a converter and return a default blank image Uri in case the image_path is empty...

How do I handle the binding to my ViewModel Uri Property best?

Is the converter the way to go and how do you handle it if you would have like many different default images which should be returned...

like image 968
silverfighter Avatar asked Apr 05 '12 11:04

silverfighter


2 Answers

Just set:

new Uri("about:blank");

Works for me.

like image 58
fandro Avatar answered Oct 23 '22 23:10

fandro


You can do something like this

Uri uri = null;
bool someValue = Context.TryGetUri(entity, out uri);
like image 1
Velin Georgiev Avatar answered Oct 24 '22 00:10

Velin Georgiev