2017-09-23 11 views
0

アンドロイドとIOSのxamarinでsdkまたはライブラリを作成できますか?また、ライブラリやSDKにもUI(ビュー)が含まれている必要があります。ライブラリやSDKに、xamarinの他のプロジェクトで使用できるビューを含めることは可能でしょうか?xamarinでandroidとiosのビューでsdk/libraryを作成することはできますか?

+0

をあなたはこのサードパーティのコンポーネントを参照することがあります。https://www.nuget.org/packages/Adapt.Presentation/、そのコードはgithubの上のオープンソースであります。 –

答えて

0

はい! Xamarin.FormsのBindable Propertiesを使用してカスタムコントロールを作成し、それをNugetパッケージにパッケージ化することができます。例えば

:あなたは別のフォルダにContentViewを作成することができますが

このような
<?xml version="1.0" encoding="UTF-8"?> 
<ContentView xmlns="http://xamarin.com/schemas/2014/forms" 
      xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
      x:Class="BindablePropertyDemo.Custom.MyCustomControl"> 
    <Grid x:Name="grid" 
      Padding="10,40,10,10" 
      HeightRequest="160" 
      VerticalOptions="Start"> 
     <Grid.RowDefinitions> 
      <RowDefinition Height="100"/> 
      <RowDefinition Height="Auto"/> 
     </Grid.RowDefinitions> 
     <Image x:Name="image" 
       HeightRequest="100" 
       HorizontalOptions="Center"/> 

     <Label x:Name="title" 
       Text="BASKETBALL" 
       Grid.Row="1" 
       FontSize="20" 
       VerticalOptions="Center" 
       TextColor="White" 
       HorizontalOptions="Center" 
       FontAttributes="Bold"/> 
    </Grid> 
</ContentView> 

MyCustomControlと呼ばれ、その後、あなたは、このような任意のページから、このコントロールを呼び出すことができます。

<?xml version="1.0" encoding="utf-8" ?> 
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" 
      xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
      xmlns:local="clr-namespace:BindablePropertyDemo" 
      xmlns:custom="clr-namespace:BindablePropertyDemo.Custom" 
      x:Class="BindablePropertyDemo.MainPage" 
      BackgroundColor="#33334c"> 
    <ScrollView> 
     <Grid RowSpacing="0"> 
      <Grid.RowDefinitions> 
       <RowDefinition Height="60"/> 
       <RowDefinition Height="Auto"/> 
      </Grid.RowDefinitions> 
      <Grid BackgroundColor="White"> 
       <Grid.ColumnDefinitions> 
        <ColumnDefinition Width="60"/> 
        <ColumnDefinition Width="*"/> 
       </Grid.ColumnDefinitions> 
       <Grid BackgroundColor="#ff4284" Padding="10"> 
        <Image Source="hamburger.png"/> 
       </Grid> 
       <Label Grid.Column="1" 
        Text="Home" 
        TextColor="#ff4284" 
        FontSize="20" 
        Margin="5,0,0,0" 
        HorizontalOptions="Start" 
        VerticalOptions="Center"/> 
      </Grid> 
      <StackLayout Spacing="0" Grid.Row="1">< 
       <!-- SEE HERE!! --> 
       <custom:MyCustomControl BackgroundColor="#76dab2" 
            TitleText="BASKETBALL" 
            Image="basketball.png"/> 

       <custom:MyCustomControl BackgroundColor="#7c57e4" 
            TitleText="FOOTBALL" 
            Image="football.png"/> 

       <custom:MyCustomControl BackgroundColor="#f1b136" 
            TitleText="GRIDIRON" 
            Image="gridiron.png"/> 
      </StackLayout> 
     </Grid> 
    </ScrollView> 
</ContentPage> 

そして、あなた次のような結果になります。

enter image description here

私はこのtutorialの例を取り上げましたが、引き続き詳細を知ることができます。

あなたがここに自分のソースコードを見つけることができます。https://github.com/mindofai/BindablePropertyDemo

関連する問題