2016-04-05 1 views
0

カスタムレンダラーなしでXamarin.Formsリストビュー(またはセル)をカスタマイズする方法はありますか?ネイティブレンダラーのないリストビューをカスタマイズする

私が見つけたすべての結果は、ネイティブレンダラで説明されていますが、私が望むものではありません。

共有プロジェクトのPCLからListViewのセルをカスタマイズし、Xamarin.Formsの機能を維持し、アプリケーション間のすべてのUIコードを共有したいだけです。

EDIT 1:

public class TappticCell : ViewCell 
{ 
    #region BindableProperty Fields 

    public static readonly BindableProperty NameProperty = 
     BindableProperty.Create("Name", typeof(string), typeof(string), ""); 

    public static readonly BindableProperty NameColorProperty = 
     BindableProperty.Create("NameColor", typeof(Color), typeof(Color), Color.Transparent); 

    #endregion 

    #region BindableProperty Properties 

    public string Name 
    { 
     get { return (string)GetValue(NameProperty); } 
     set { SetValue(NameProperty, value); } 
    } 

    public Color NameColor 
    { 
     get { return (Color)GetValue(NameColorProperty); } 
     set { SetValue(NameColorProperty, value); } 
    } 

    #endregion 

    #region Fields 

    private readonly Label _nameLabel; 
    private readonly StackLayout _stackLayout; 

    #endregion 

    #region Constructors 

    public TappticCell() 
    { 
     [...] 
     _nameLabel = new Label { HorizontalOptions = LayoutOptions.CenterAndExpand }; 

     _nameLabel.SetBinding(Label.TextProperty, "Name"); 
     _nameLabel.SetBinding(Label.TextColorProperty, "NameColor"); 

     [...] 
    } 

    #endregion 
} 

私の問題は、XAML

<cells:TappticCell Image="{Binding Image}" 
          Name="{Binding Name}" 
          BackgroundColor="Gray" 
          NameColor="{Binding Favorite, Converter={StaticResource BooleanToColor}}" 
          TextSize="30" /> 

私はImageCellでこれを使用しての私の使用ここでは... BindableProperty NameColorを有する第二SetBindingが動作しないですそれは素晴らしいですが、私のカスタムセルではありません...

ありがとう

+0

XAMLやコードでやりたいですか? 'ListView.ItemTemplate'を見てください –

答えて

0

よく私はあなたをはっきりと理解すれば、細胞の外観をカスタマイズしたいと思う。 その場合は、UIコンテンツを表示するためにviewCellを使用することをお勧めします。ここ は、uはあなたの選択であるかもしれないviewCellクラス

public class EffortMenuCell:ViewCell 
    { 
     static int i = 0; 
     public EffortMenuCell() : base() { 

      var newLabel2 = new Label() {VerticalOptions = LayoutOptions.CenterAndExpand }; 


      newLabel2.SetBinding (Label.TextProperty, "nameLabel"); 
      var time = new Label(); 
      time.HorizontalOptions = LayoutOptions.EndAndExpand; 
      time.VerticalOptions = LayoutOptions.CenterAndExpand; 
      time.SetBinding (Label.TextProperty, "timespan"); 
      var tempLayout2 = new StackLayout(); 

      //tempLayout2.BackgroundColor = Color.White; 
      tempLayout2.Padding = new Thickness(20,0,20,0); 
      tempLayout2.Spacing = 20; 

      tempLayout2.Orientation = StackOrientation.Horizontal; 

// based on index Different Row appearance , 

      if (i == 0) { 
       tempLayout2.BackgroundColor = Color.FromHex ("e0e0e0"); 
       newLabel2.TextColor = Color.FromHex ("a4a4a4"); 
       time.TextColor = Color.FromHex ("01bcbc"); 
       this.IsEnabled = false; 
       i++; 
      } else { 
       if (i <= 4) { 
        tempLayout2.BackgroundColor = Color.White; 
        newLabel2.TextColor = Color.Black; 
        time.TextColor = Color.FromHex ("007fbf"); 
        i++; 
       } 
       if (i == 5) { 
        i = 0; 
       } 
      } 

      tempLayout2.Children.Add (newLabel2); 
      tempLayout2.Children.Add (time); 
      this.View = tempLayout2; 
     } 
    } 
+0

はい、まさに私がやりたいことです!ありがとう!私は、プラットフォーム間で統一されたUIを得るためにカスタムレンダラを実行しなければならないと思いました! – Jones605

+0

私はこれがあなたを助けたので答えを受け入れることを期待します。 –

+0

はい:しかし私は別の質問があります!ラベルのバインドに問題がありました。私のコードで私の質問を編集:) – Jones605

0

Effectsを書く方法です。

エフェクトを使用すると、各プラットフォームのネイティブコントロールをカスタマイズでき、通常は小さなスタイル変更に使用されます。この記事では、エフェクトの概要、エフェクトとカスタムレンダラーの境界線の概要、およびPlatformEffectクラスについて説明します。

リストビューを完全に制御するには、レンダラーがまだ必要です。

関連する問題