【发布时间】:2021-04-14 21:41:42
【问题描述】:
我有一个用于 iOS 的自定义编辑器,但对于 UWP,我使用另一个名为 SfRichTextEditor 的编辑器。
现在我想知道如何像可共享类一样创建,因为它们具有相同的可绑定属性,而不是像我目前所做的那样,即在它们之上创建 ContentView,这导致:
-
出于性能目的的不必要的嵌套
-
重复代码
-
某些绑定似乎有问题(未验证,但有些奇怪)。
<ContentView> <OnPlatform x:TypeArguments="View"> <OnPlatform.Platforms> <On Platform="iOS"> <controls:CustomIOSEditor/> </On> <On Platform="UWP"> <controls:CustomUWPEditor/> </On> </OnPlatform.Platforms> </OnPlatform> </ContentView>
因此,如果可能,我希望有一个可共享的基类来重用代码,而不是这种方法。
这些是我今天拥有的 x2 控件。
我的 iOS 自定义控件:
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);
}
}
我的 UWP 自定义控件:
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);
}
}
【问题讨论】:
-
现在检查。所以这是我强调的,前两个你可以忽略
-
是的,我做到了。还重新启动了视觉工作室。还是同样的问题。
-
顺便说一句,我使用 xamarn 表单。
-
是的,我当然知道 XF(否则就没有意义),.__MACOS__。似乎按预期工作,代码中的一切似乎都很好,抱歉我现在不知道。
-
好的。我不需要更改任何特定于 MacOS 的内容?
标签: c# xamarin xamarin.forms custom-controls multitargeting