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. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Check if Imagesource exist

Thread ID:

Created:

Updated:

Platform:

Replies:

149662 Dec 4,2019 04:32 PM UTC Dec 5,2019 01:11 PM UTC Xamarin.Forms 1
loading
Tags: SfAvatarView
MOHAMED FKI
Asked On December 4, 2019 04:32 PM UTC

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. 




Hemalatha Marikumar [Syncfusion]
Replied On 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. 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon