We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Check if Imagesource exist

hello.


I want to know if the SfavatarView check if imagsourceUri exist or not.

if he doesn't exist, he will display characters.

which best way within I can proceed. 




1 Reply

HM Hemalatha Marikumar Syncfusion Team December 5, 2019 01:11 PM UTC

Hi Mohamed FKI, 

Greetings from Syncfusion. 

We have validated your query and prepared a sample based on your requirement. Please find the sample from the link below.
 
 
 
Here, validating the provided URI and return null to the ImageSource of AvatarView. After that ensure and update the desired text to it as per in below code snippet

 
Code Snippet[C#]: URL validation

 
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)

 
        { 
            try 
            { 
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(value.ToString()); 
                HttpWebResponse response = (HttpWebResponse)request.GetResponse(); 
                if (response != null && response.StatusCode == HttpStatusCode.OK) 
                { 
                    return value.ToString(); 
                } 
                else 
                { 
                    return null; 
                } 
            } 
            catch (Exception exception) 
            { 
                return null; 
            } 
        } 
 
In this sample, we have set the valid URL to display the Image for AvatarView. If you change invalid URL its Avatar view display characters. 
 
Code Snippet [C#] : Change AvatarType 

private void ChangeType()
 
        { 
            if (avatar.ImageSource == null) 
            { 
                avatar.ContentType = ContentType.Initials; 
                avatar.AvatarName = "Alex"; 
                avatar.InitialsType = InitialsType.SingleCharacter; 
                avatar.InitialsColor = Color.Black; 
                avatar.BackgroundColor = Color.Bisque; 
            } 
        } 


 
Please let us know if you have any concerns, 
 
Regards, 
Hemalatha M. 


Loader.
Live Chat Icon For mobile
Up arrow icon