locked
How to access the Corner Radius Property In IValueConverter ? RRS feed

  • Question

  • User266661 posted

    My Custom Renderer for Corner Radius is ... public class ContentViewRoundedCorners : StackLayout { public static readonly BindableProperty CornerRaidusProperty = BindableProperty.Create(x => x.CornerRadius, 15);

        public float CornerRadius
        {
            get { return (float)GetValue(CornerRaidusProperty); }
            set { SetValue(CornerRaidusProperty, value); }
        }
    }
    

    And My IValue Converter code is .. public class StripedBackgroundIndexConverter : IValueConverter {

        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value == null || parameter == null) return Color.White;
            var index = ((ListView)parameter).ItemsSource.Cast<object>().ToList().IndexOf(value);
    
            var counterlistview = ((ListView)parameter).ItemsSource.Cast<object>().ToList().Count-1;
    
    
    
            // return index  == counterlistview ?  //How to check the corner radius here ...  ;
    
        }
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
    

    Now the question is how to access the corner radius in the conditional statement give above in the IValueConverter portion ?

    Monday, December 5, 2016 8:49 AM

Answers

  • User2148 posted

    Yes @Andrew1993 . I think in you prj there is a point where you call

    ObservableCollection<MyModel> oc =await CallWebService();
    

    then you can do

    oc[0].IsFirstOrLast = true;
    oc[oc.Count -1].IsFirstOrLast = true;
    
    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Tuesday, December 6, 2016 5:55 PM

All replies

  • User13529 posted

    @Andrew1993 why cast to listview? If you custom render if a stacklayout?

    I think there something don't fit here. Converter code working?

    Tuesday, December 6, 2016 8:19 AM
  • User266661 posted

    Because I want only first and last view cell in rounded shape.That's why I'm using ListView .@josemmortega

    Tuesday, December 6, 2016 8:26 AM
  • User2148 posted

    @andrew1993 can you post a full repo on github?

    Tuesday, December 6, 2016 9:26 AM
  • User266661 posted

    https://github.com/asfend/App3 @AlessandroCaliaro .. Here's the link of repository ..

    Tuesday, December 6, 2016 10:17 AM
  • User2148 posted

    @andrew1993 add a pull request... take a look

    Tuesday, December 6, 2016 11:02 AM
  • User266661 posted

    Thanks @AlessandroCaliaro for your support but As I already mentioned that the listview data is dynamic means there's some backend service involved.The code I've sent you via github repository is just a quick look or a sample ? You have set IsFirstOrDafault = true in my listview first and last itemsource value.Well that's not the case what if the data changes then the current logic will not work .. Hope you understand my question now ..

    Tuesday, December 6, 2016 5:35 PM
  • User2148 posted

    Yes @Andrew1993 . I think in you prj there is a point where you call

    ObservableCollection<MyModel> oc =await CallWebService();
    

    then you can do

    oc[0].IsFirstOrLast = true;
    oc[oc.Count -1].IsFirstOrLast = true;
    
    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Tuesday, December 6, 2016 5:55 PM
  • User266661 posted

    @AlessandroCaliaro ... As you mentioned that the corner radius is same just like a color converter.But I get the following error after Binding with XAML.

    Position 30:15. Cannot assign property "CornerRadius": type mismatch between "Xamarin.Forms.Binding" and "System.Single"

    Thursday, December 8, 2016 9:33 AM
  • User2148 posted

    have you pushed your prj? can I download it?

    Thursday, December 8, 2016 9:35 AM
  • User266661 posted

    https://github.com/asfend/RoundedCornerRadius Yeah @AlessandroCaliaro ... here's the link of repository ...

    Thursday, December 8, 2016 9:56 AM
  • User2148 posted

    Sorry, I don't know... maybe this could help you https://forums.xamarin.com/discussion/47496/custom-bindable-property-type-mismatch

    Thursday, December 8, 2016 9:40 PM