I have created custom bordered stacklayout for android using custom renderer. The StackLayout border is created by using xml file. The border color is defined in that xml file. But I want to change that border color dynamically at runtime using bindable object property. I have done this with ios. But i dont have any idea how to bind the bindable object to the xml file. My customBorderStacklayout sample code is mentioned below, Please share your valuable suggestion to done this.
CustomStackBorder.cs
public class CustomStackBorder : StackLayout
{
public Color BorderColor
{
get { return (Color)GetValue(BorderColorProperty); }
set { SetValue(BorderColorProperty, value); }
}
public static readonly BindableProperty BorderColorProperty =
BindableProperty.Create("BorderColor", typeof(Color), typeof(CustomStackBorder), Color.Gray, BindingMode.TwoWay);
public CustomStackBorder()
{
}
}
CustomStackLayoutRenderer.cs (Android)
public class CustomStackLayoutRenderer : VisualElementRenderer<StackLayout>
{
public CustomStackLayoutRenderer(Context context) : base(context)
{
}
protected override void OnElementChanged(ElementChangedEventArgs<StackLayout> e)
{
base.OnElementChanged(e);
Background = ContextCompat.GetDrawable(this.Context, Resource.Drawable.StackLayoutBorder);
}
}
StackLayoutBorder.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<stroke android:width="0.1dp" android:color="#ff555555"></stroke>
<corners android:topLeftRadius="2dp"
android:topRightRadius="2dp"
android:bottomLeftRadius="2dp"
android:bottomRightRadius="2dp" />
<solid android:color="#ffffff"/>
</shape>