2017-11-06 9 views
1

私は、アプリケーション全体で使用する必要があるカスタムビュー(ラベルと垂直スタックのエントリ)を作成したいと考えています。要件には、エントリにテキストがない場合、上記のラベルは非表示にする必要があり、その逆も同様です。コンテンツビューを作成しようとしましたが、xamlからカスタムコントロールを使用しているときに可視性を設定できません。Xamarin Forms App全体で使用するカスタムビューの作成

CustomControl

using System; 
using System.Collections.Generic; 
using Xamarin.Forms; 

namespace iTrans.CustomControls 
{ 
    public partial class LabelEditor : ContentView 
    { 
     public LabelEditor() 
     { 
      InitializeComponent(); 
     } 

     void Handle_TextChanged(object sender, Xamarin.Forms.TextChangedEventArgs e) 
     { 
      if (string.IsNullOrEmpty(entry.Text)) 
       label.IsVisible = false; 
      else 
       label.IsVisible = true; 
     } 
    } 
} 

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="iTrans.CustomControls.LabelEditor"> 
    <ContentView.Content> 
     <Label x:Name="label"></Label> 
     <Entry x:Name="entry" TextChanged="Handle_TextChanged"/> 
    </ContentView.Content> 
</ContentView> 

使用法:

<custom:LabelEditor EditorText="hello" LabelText="bye"/> 

答えて

1

あなたは、カスタムビューにラベルテキストのエディタテキストと1対1にいくつかのバインド可能なプロパティを追加する必要があります。

This blog postこれを行う方法を説明します。

関連する問題