I have a .Net MAUI application. It has a page where I use some custom handlers (custom renderers sort of) as my controls. For example, I have a label that is overwritten with some code to create a border around it:
Microsoft.Maui.Handlers.LabelHandler.LabelMapper.AppendToMapping(nameof(IView.Background), (handler, view) =>
{
if (view is CustomHandlerLabelPriceTag)
{
#if __ANDROID__
handler.NativeView.SetBackgroundColor(Colors.Red.ToNative());
var gradientDrawable = new GradientDrawable();
gradientDrawable.SetCornerRadius(70f);
gradientDrawable.SetStroke(5, global::Android.Graphics.Color.ParseColor(SharedAppMethods.GetColorByKey("ColorPriceTag")));
gradientDrawable.SetColor(global::Android.Graphics.Color.ParseColor(SharedAppMethods.GetColorByKey("ColorBackground")));
handler.NativeView.SetBackgroundDrawable(gradientDrawable);
handler.NativeView.SetPadding(handler.NativeView.PaddingLeft, handler.NativeView.PaddingTop, handler.NativeView.PaddingRight, handler.NativeView.PaddingBottom);
#elif __IOS__
handler.NativeView.BackgroundColor = Colors.Red.ToNative();
handler.NativeView.BorderStyle = UIKit.UITextBorderStyle.Line;
handler.NativeView.Layer.CornerRadius = 30;
handler.NativeView.Layer.BorderWidth = 3f;
handler.NativeView.Layer.BorderColor = Color.FromArgb(SharedAppMethods.GetColorByKey("ColorPriceTag")).ToCGColor();
handler.NativeView.Layer.BackgroundColor = Color.FromArgb(SharedAppMethods.GetColorByKey("ColorBackground")).ToCGColor();
handler.NativeView.LeftView = new UIKit.UIView(new CGRect(0, 0, 0, 0));
handler.NativeView.LeftViewMode = UIKit.UITextFieldViewMode.Always;
#endif
}
It has this class, nothing much is needed here:
using Microsoft.Maui.Controls;
namespace SheeperMAUI.CustomHandlers
{
internal class CustomHandlerLabelPriceTag : Label
{
}
}
This is how I use it in the XAML code on my page:
<customHandler:CustomHandlerLabelPriceTag
Text="{Binding text}" FontSize="15"
Padding="9,0,9,0" TextColor="{StaticResource ColorText}"
HorizontalOptions="CenterAndExpand"
VerticalOptions="Center" HorizontalTextAlignment="Center"
VerticalTextAlignment="Center"/>
MY QUESTION: I want to able to pass a string in the XAML code above (by binding it to a string I already have ie. using {Binding ...}) to the custom handler where that string will be used to set the border color in the custom handler code. I only have to know how to pass that value, the rest I can solve myself ;) Is this possible?
Thanks!