前提・実現したいこと
XamarinのUIのコンポーネントを作りたいです。
試したこと
XamarinのUIのコンポーネントを作りたいです。
- Plugins for Xamarinからテンプレートを作成
- C#でLabelやEntryといったコントロールを定義したものをパッケージ化
- 他プロジェクトから呼び出す
といったことはできました。
しかし可能であれば、xamlでUIを作り、呼び出せるようしたいと考えています。
xamlを追加し、ルートをcontentViewに変更するなどしてみましたが、
呼び出した際にエラーこそでないものの、画面に表示されません。
- xamlから作ることは可能でしょうか?
- その場合通常プロジェクトで画面を作るときと異なる点はどこになるでしょうか?
以下ソースコードです
【Feature1プロジェクト】View1.xaml
<?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="Plugin.Feature1.View1"> <ContentView.Content> <StackLayout HorizontalOptions="Center" VerticalOptions="Center" BackgroundColor="Black"> <Label Text="Hello Xamarin.Forms!" TextColor="White"/> </StackLayout> </ContentView.Content> </ContentView>
【Feature1プロジェクト】View1.xaml.cs
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Xamarin.Forms; using Xamarin.Forms.Xaml; namespace Plugin.Feature1 { [XamlCompilation(XamlCompilationOptions.Compile)] public partial class View1 : ContentView { public View1 () { InitializeComponent (); } } }
【Feature1プロジェクト】IFeature1.shared.cs
using Xamarin.Forms; namespace Plugin.Feature1 { public interface IFeature1 { } }
【Testプロジェクト】MainPage.xaml
<?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:hoge="clr-namespace:Plugin.Feature1;assembly=Plugin.Feature1" x:Class="Test.Views.MainPage" Title="{Binding Title}"> <StackLayout HorizontalOptions="CenterAndExpand" VerticalOptions="CenterAndExpand"> <hoge:View1/> </StackLayout> </ContentPage>
【Testプロジェクト】MainPage.xaml.cs
using Xamarin.Forms; using Plugin.Feature1; namespace Test.Views { public partial class MainPage : ContentPage { public MainPage () { InitializeComponent (); } } }
よろしくお願い致します。
回答1件
あなたの回答
tips
プレビュー