2017-08-28 15 views
0

私は解決できない問題があります。多分あなたは私を助けることができます。私は、xamarin形式のエントリのための柔軟な下線を作成したい。私のcustomEntryのBackgroundColorを透明に設定すると、下線は消えますが、私はそれを現れるように戻すことはできません。私はちょうど底のために働かなかった新しい境界を設定するか、または新しいBackgroundColorを設定するような、いくつかのことを試しました。 Googleも私を助けなかった。 アイデアはありますか?その問題を解決するにはどうすればよいですか?もう一度下線を引いて

マイPCL

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using System.Threading.Tasks; 
using Xamarin.Forms; 

namespace MultiBaseCS_Mobile 
{ 
    public class CustomEntryCell : Entry 
    { 

     public static readonly BindableProperty HasUnderlineProperty = 
      BindableProperty.Create(nameof(HasUnderline), typeof(bool), typeof(CustomEntryCell), true); 

     public CustomEntryCell() 
     { 
     } 

     public bool HasUnderline 
     { 
      get { return (bool)GetValue(HasUnderlineProperty); } 
      set { SetValue(HasUnderlineProperty, value); } 
     } 

    } 
} 

私customRendererここ

using Xamarin.Forms; 
using MultiBaseCS_Mobile; 
using MultiBaseCS_Mobile.Droid; 
using Xamarin.Forms.Platform.Android; 
using Android.Text; 
using System.ComponentModel; 
using Android.Graphics.Drawables; 
using Android.Graphics; 

[assembly: ExportRenderer(typeof(CustomEntryCell), typeof(CustomEntryRenderer))] 

namespace MultiBaseCS_Mobile.Droid 
{ 
    public class CustomEntryRenderer : EntryRenderer 
    { 
     protected override void OnElementChanged(ElementChangedEventArgs<Entry> e) 
     { 
      base.OnElementChanged(e); 

      var entry = (CustomEntryCell)Element; 

      if (entry != null) 
      { 
       if (!entry.HasUnderline) 
       { 
        Control.SetBackgroundColor(Android.Graphics.Color.Argb(0, 0, 0, 0)); 
       } 

      } 
     } 



     protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e) 
     { 
      base.OnElementPropertyChanged(sender, e); 
      var entry = (CustomEntryCell)Element; 

      if (e.PropertyName == CustomEntryCell.HasUnderlineProperty.PropertyName) 
      { 
       if (!entry.HasUnderline) 
       { 
        Control.SetBackgroundColor(Android.Graphics.Color.Argb(0, 0, 0, 0)); 
       } 
       else 
       { 
        // Underline should appear 
       } 


      } 
     } 
    } 
} 
+0

を試すことができるものであるあなたに

ありがとうございました現れる ? –

答えて

0

はあなたが戻ってそれを "持って来る" しようとしない方法を

using Xamarin.Forms; 
using MultiBaseCS_Mobile; 
using MultiBaseCS_Mobile.Droid; 
using Xamarin.Forms.Platform.Android; 
using Android.Text; 
using System.ComponentModel; 
using Android.Graphics.Drawables; 
using Android.Graphics; 

[assembly: ExportRenderer(typeof(CustomEntryCell), typeof(CustomEntryRenderer))] 

namespace MultiBaseCS_Mobile.Droid 
{ 
    public class CustomEntryRenderer : EntryRenderer 
    { 
     InsetDrawable originalBackgroundDrawable = null; 

     protected override void OnElementChanged(ElementChangedEventArgs<Entry> e) 
     { 
      base.OnElementChanged(e); 

      originalBackgroundDrawable = Control.Background as InsetDrawable; 

      var entry = (CustomEntryCell)Element;  
      if (entry != null) 
      { 
       if (!entry.HasUnderline) 
       { 
        Control.SetBackground(null); 
       } 

      } 
     } 



     protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e) 
     { 
      base.OnElementPropertyChanged(sender, e); 

      var entry = (CustomEntryCell)Element;  
      if (e.PropertyName == CustomEntryCell.HasUnderlineProperty.PropertyName) 
      { 
       if (!entry.HasUnderline) 
       { 
        Control.SetBackgroundColor(null); 
       } 
       else 
       { 
        // Underline should appear 
        Control.SetBackgroundColor(originalBackgroundDrawable); 
       } 


      } 
     } 
    } 
} 
+0

ありがとう、それはまさに私が探していたものです。 –

関連する問題