Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 77050

Change the ListView's item template depending a condition on Model

$
0
0

ListView list = new ListView { Style = Styles.DefaultList };

listView.SetBinding (ItemsView.ItemsSourceProperty, "MenuItems");
listView.SetBinding (ItemsView.ItemTemplateProperty, "MenuItems", converter: new ItemSourceToDataConverter( ));

public class SubMenuPadding : IValueConverter
{
    public object Convert (object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        if(((ObservableCollection<MenuItem>)value).Where (item => item.changeTemplate == true ))
            return new DataTemplate (typeof(SecondTemplate));

        return new DataTemplate (typeof(FirstTemplate));
    }

    public object ConvertBack (object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        return value;
    }
}

Somethind like this.. But it don't work.
Depending a property state on model, I change the DataModel.


Viewing all articles
Browse latest Browse all 77050

Trending Articles