2017-04-17 77 views
1

使用Visual Studio时,选择'Xamarin Zebble - 跨平台解决方案'时,将会创建一个默认项目,其中包含五页。我修改了第五页来实现签名板。以下是Page-5.zbl的代码。如何替换Zebble SignaturePad UI组件或添加并使用另一个SignaturePad组件?

<?xml version="1.0"?> 

<z-Component z-type="Page5" z-base="Templates.Default" z-namespace="UI.Pages" 
    z-partial="true" Title="About us" data-TopMenu="MainMenu" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:noNamespaceSchemaLocation="./../.zebble-schema.xml"> 

    <z-place inside="Body"> 

    <TextView Text="Hello world!" /> 
    <SignaturePad Id="sigPad1" Enabled="true" LineThickness="4" Style.Border.Color="red" Style.Width="100" Style.Height="100"/> 

    </z-place> 

</z-Component> 

这最终加入这行来.zebble-generated.cs

await Body.Add(sigPad1 = new SignaturePad { Id = "sigPad1", Enabled = true, LineThickness = 4 } 
    .Set(x => x.Style.Border.Color = "red") 
    .Set(x => x.Style.Width = 100) 
    .Set(x => x.Style.Height = 100)); 

我一直在寻找这个SignaturePad组件包:https://github.com/xamarin/SignaturePad

如果我想用Xamarian SignaturePad组件或任何其他人的SignaturePad组件代替Zebble SignaturePad UI组件,我该怎么做?

回答

0

要使用第三方组件,您需要做的就是围绕它创建一个Zebble包装。它在这里解释: http://zebble.net/docs/customrenderedview-third-party-native-components-plugins

第1步:创建本机适配器(S)

,必须先创建一个Zebble视图类使用下面的模式来代表你的组件的一个实例。该课程将在共享项目中提供给所有3个平台。

namespace Zebble.Plugin 
{ 
    partial class MyComponent : CustomRenderedView<MyComponentRenderer> 
    { 
     // TODO: Define properties, method, events, etc. 
    } 
} 

注:要使VS智能感知中ZBL文件认识到这一点,你应该为MyComponent的还有一个.ZBL文件:

<z-Component z-type="MyComponent" z-base="CustomRenderedView[MyComponentRenderer]" z-namespace="Zebble.Plugin" 
    z-partial="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:noNamespaceSchemaLocation="./../.zebble-schema.xml" /> 

下一步将是创建渲染器类。

第2步:创建本机渲染器 您需要为每个平台(UWP,iOS,Android)创建以下类。

public class MyComponentRenderer : ICustomRenderer 
    { 
     MyComponent View; 
     TheNativeType Result; 

     public object Render(object view) 
     { 
      View = (MyComponent)view; 
      Result = new TheNativeType(); 
      // TODO: configure the properties, events, etc. 
      return Result; 
     } 

     public void Dispose() => Result.Dispose(); 
} 

在应用程序代码 在应用程序代码(App.UI),可以使用MyComponent的,就像任何其他的内置或自定义视图类型使用它。

<Zebble.Plugin.MyComponent Id="..." Property1="..." on-Event1="..." /> 
+0

我目前有创建一个新的'Zebble for Xamarin - 跨平台解决方案'时默认创建的文件夹/文件解决方案布局结构。关于第1步的文本,“这个类将在共享项目中”,你和/或Zebble的文档将共享项目定义为什么?以便我可以了解你建议我创建班级的位置。我浏览过网站,只看到了“App.Domain”和“App.UI”的定义。 – HappyCoding

+1

App.Doman和App.UI项目都是Visual Studio中的“共享源”项目类型,并且这些项目中的任何代码在特定于平台的可运行项目(UWP,Android,iOS)中在逻辑上也是“存在”的。 – Paymon

+1

在你的情况下,App.UI在编写代码时是个正确的地方。 – Paymon

相关问题