Search code examples
xamarinwindows-phonexamarin.forms

Xamarin form, Add border color for 'Image' Control for Windows 8 application


I am developing a mobile application using Xamarin Forms, I want to add borders to the image dynamically based on data.

On iOS, Android applications, using renderers, I can add border colors.

But on Windows 8 application, I cannot add the border. I think it is because of System.Widows.Controls.Image does not have a property to set the borders thickness and border color.

is there any way to add the border to the image on Renderer of Windows Phone application?


Solution

  • I'm currently not able to provide you a detailed example, but this is how it should work:

    Create a renderer for Windows Phone. In the OnElementChanged method override you can create a 'native' Windows Phone border element, add the image to the border and after that call the SetNativeControl(border); method to add the border with the image inside it.

            var border = new Border() {BorderBrush = Colors.Red, BorderThickness = new Thickness(10)};
            border.Child = new Image();
    
            SetNativeControl(border);