2016-06-16 9 views

答えて

0
Entry entry = new Entry(); 

// Hide it 
entry.IsVisible = false; 
2

多くの入力フィールドの上に展開/折りたたみアイコンを使用して同様の問題を解決しました。ビューモデルは、コマンドを処理

<Image Source="{Binding ShowHideIcon, Converter={StaticResource StringToResImageSourceConverter}}" WidthRequest="20" HeightRequest="20""> 
    <Image.GestureRecognizers> 
     <TapGestureRecognizer Command="{Binding ShowHideCommand}" /> 
    </Image.GestureRecognizers> 
</Image> 

XAMLで

表示/非表示素子

はPCLの埋め込みリソースを参照すると、固定サイズ(20×20)とのクリック可能な画像を追加します

画像がタッチされるたびにブール値を切り替えます。 XAML

public bool EntryVisible { get; set; } 

public Command ShowHideCommand{ 
    get { 
     return new Command((object o) => { 
      EntryVisible = !EntryVisible; 
      if (EntryVisible) { 
       ShowHideIcon = "ic_collapse"; 
      } else { 
       ShowHideIcon = "ic_expand"; 
      } 
     } 
    } 
} 

ラベルおよびエントリ

バインドビューモデルのbooleanへのラベルおよびエントリの属性のisVisible。完全性期すため

<Label Text="Quantity" IsVisible="{Binding EntryVisible}" /> 
<Entry Text="{Binding Quantity}" IsVisible="{Binding EntryVisible}" /> 

、私はPCL Resourcesフォルダ内の画像ic_expand.pngic_collapse.pngを保存するためにhttps://developer.xamarin.com/guides/xamarin-forms/working-with/images/#Embedded_Imagesを使用しています。

A文字列を変換するためにコンバータが必要です。 "ic_expand"をXAMLが使用できるイメージ参照に変換します。

public class StringToResImageSourceConverter : IValueConverter { 
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { 
     var resString = (string)value; 
     if (!string.IsNullOrEmpty(resString)) { 
      return ImageSource.FromResource("ProjectName.Resources." + resString + ".png"); 
     } 
     return null; 
    } 

    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { 
     throw new NotImplementedException(); 
    } 
} 
関連する問題