I have a custom editor that I use for iOS, but for UWP I use another editor called SfRichTextEditor
.
Now I wonder how I can create like a shareable class, since they have the same bindableproperties instead of doing what I currently do, which is creating a ContentView
on top of them, which is causing:
unnecessary nesting for performance purposes
duplicate code
seems to have trouble with some bindings (not verified, but something strange).
<ContentView> <OnPlatform x:TypeArguments="View"> <OnPlatform.Platforms> <On Platform="iOS"> <controls:CustomIOSEditor/> </On> <On Platform="UWP"> <controls:CustomUWPEditor/> </On> </OnPlatform.Platforms> </OnPlatform> </ContentView>
So instead of this approach, I want to have a shareable base class if possible, to reuse the code.
These are the x2 controls that I have today.
My iOS custom control:
public class CustomIOSEditor : Editor // Using regular xamarin editor
{
public static readonly BindableProperty StringResultCommandProperty =
BindableProperty.Create(
nameof(StringResultCommand),
typeof(ICommand),
typeof(CustomIOSEditor),
default(ICommand));
public object StringResultCommandParameter
{
get => GetValue(StringResultCommandParameterProperty);
set => SetValue(StringResultCommandParameterProperty, value);
}
}
My UWP custom control:
public class CustomUWPEditor : SfRichTextEditor // Using SfRichTextEditor instead here.
{
public static readonly BindableProperty StringResultCommandProperty =
BindableProperty.Create(
nameof(StringResultCommand),
typeof(ICommand),
typeof(CustomUWPEditor),
default(ICommand));
public object StringResultCommandParameter
{
get => GetValue(StringResultCommandParameterProperty);
set => SetValue(StringResultCommandParameterProperty, value);
}
}