My Custom Renderer for Corner Radius is ...
public class ContentViewRoundedCorners : StackLayout
{
public static readonly BindableProperty CornerRaidusProperty =
BindableProperty.Create<ContentViewRoundedCorners, float>(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 ?
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;
Answers
@Andrew1993 why cast to listview? If you custom render if a stacklayout?
I think there something don't fit here. Converter code working?
Because I want only first and last view cell in rounded shape.That's why I'm using ListView .@josemmortega
@andrew1993 can you post a full repo on github?
https://github.com/asfend/App3
@AlessandroCaliaro .. Here's the link of repository ..
@andrew1993 add a pull request... take a look
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 ..
Yes @Andrew1993 . I think in you prj there is a point where you call
then you can do
@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"
have you pushed your prj? can I download it?
https://github.com/asfend/RoundedCornerRadius
Yeah @AlessandroCaliaro ... here's the link of repository ...
Sorry, I don't know... maybe this could help you
https://forums.xamarin.com/discussion/47496/custom-bindable-property-type-mismatch