2017-12-22 23 views
0

以下のようにカスタムレンダラを使用してアンドロイド用のカスタムラジオボタンを作成しました。以下の警告が出力ウィンドウに表示されます。私は多くの方法を試して、多くのサイトを挙げましたが、この警告を修正する明確な解決策はありません。誰もがナゲットのバージョンを変更せずに提案をすることはできますか?Xamarin.Formsでバインド可能なプロパティの警告をクリアする方法

public static BindableProperty ItemsSourceProperty = 
       BindableProperty.Create<BindableRadioGroup, IEnumerable> 
       (o => o.ItemsSource, default(IEnumerable), propertyChanged: OnItemsSourceChanged); 

     public static BindableProperty SelectedIndexProperty = 
      BindableProperty.Create<BindableRadioGroup, 
       int>(o => o.SelectedIndex, default(int), BindingMode.TwoWay, 
       propertyChanged: OnSelectedIndexChanged); 

public IEnumerable ItemsSource 
     { 
      get { return (IEnumerable)GetValue(ItemsSourceProperty); } 
      set { SetValue(ItemsSourceProperty, value); } 
     } 


     public int SelectedIndex 
     { 
      get { return (int)GetValue(SelectedIndexProperty); } 
      set { SetValue(SelectedIndexProperty, value); } 
     } 


private static void OnItemsSourceChanged(BindableObject bindable, IEnumerable oldvalue, IEnumerable newvalue) 
     { 
      var radButtons = bindable as BindableRadioGroup; 

      radButtons.rads.Clear(); 
      radButtons.Children.Clear(); 
      if (newvalue != null) 
      { 

       int radIndex = 0; 
       foreach (var item in newvalue) 
       { 
        var rad = new CustomRadioButton(); 
        rad.Text = item.ToString(); 
        rad.Id = radIndex; 

        rad.CheckedChanged += radButtons.OnCheckedChanged; 

        radButtons.rads.Add(rad); 

        radButtons.Children.Add(rad); 
        radIndex++; 
       } 
      } 
     } 

private static void OnSelectedIndexChanged(BindableObject bindable, int oldvalue, int newvalue) 
     { 
      if (newvalue == -1) return; 

      var bindableRadioGroup = bindable as BindableRadioGroup; 

      foreach (var rad in bindableRadioGroup.rads) 
      { 
       if (rad.Id == bindableRadioGroup.SelectedIndex) 
       { 
        rad.Checked = true; 
       } 
      } 
     } 

Displayed Warning Screenshot

答えて

0

警告メッセージが明確にBindableProperty.Createのジェネリック版が廃止されていることを述べています。

は、ここでは、非ジェネリックバージョンを使用して、あなたのItemsSourcePropertyに基づく例です:

public static readonly BindableProperty ItemsSourceProperty = 
      BindableProperty.Create(
       propertyName: nameof(ItemsSource), 
       returnType: typeof(IEnumerable)), 
       declaringType: typeof(BindableRadioGroup), 
       propertyChanged: OnItemsSourceChanged); 

だからあなたBindableProperty宣言を書き換えるや警告(推奨されません)を抑制。
これを行う方法がまだわからない場合は、official guideを参照してください。あなたの助けの@EvZため​​

+0

を警告、私は次のエラーを得たことをクリアしている...のpublic static BindableProperty ItemsSourceProperty = BindableProperty.Create(がNameOf (ItemsSource)、型(CustomRadioButton)、 null、propertyChanged:OnItemsSourceChanged)); ..... 'object'に 'GetEnumetator'のパブリック定義が含まれていないため、foreach文は 'object'型の変数に対しては機能しません – Karthick

+0

あなたの提案として変更しましたが、エラーは明確ではありません。 – Karthick

+0

私の答えを編集しました。 – EvZ

0

おかげで、私はこのように使用すると、このよう

public static BindableProperty ItemsSourceProperty = 
     BindableProperty.Create(propertyName: nameof(ItemsSource), 
      returnType: typeof(IEnumerable), declaringType: typeof(BindableRadioGroup), 
      propertyChanged: OnItemsSourceChanged); 


private static void OnItemsSourceChanged(BindableObject bindable, object oldvalue, object newvalue) 
{ 
    var radButtons = bindable as BindableRadioGroup; 

    radButtons.rads.Clear(); 
    radButtons.Children.Clear(); 
    if (newvalue != null) 
    { 
     var value = newvalue as IEnumerable; 
     int radIndex = 0; 
     foreach (var item in value) 
     { 
      var rad = new CustomRadioButton(); 
      rad.Text = item.ToString(); 
      rad.Id = radIndex; 

      rad.CheckedChanged += radButtons.OnCheckedChanged; 

      radButtons.rads.Add(rad); 

      radButtons.Children.Add(rad); 
      radIndex++; 
     } 
    } 
} 
関連する問題