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

ListView GroupHeaderTemplate Capture and alter Switch Control on all header cells

$
0
0

Hope someone could help with this issue. I have a list view that uses Grouping Headers based on a key (Order ID). This group all items information under that order together. In the header is a switch control. The aim is to (somehow) disable all switches and then only activate the last switch enabled. Also i need to capture the order id of the switch enabled. Similar to item select but from an header context. I've attached what the visual of the list view looks like.

This is the binding code for the ListView:

lvOrderOnline = new ListView
            {
                IsGroupingEnabled = true,
                GroupDisplayBinding = new Binding("Key"),
                GroupHeaderTemplate = new DataTemplate(typeof(Models.ListViewGroupHeaderCell)),
                HasUnevenRows = true,
                ItemTemplate = new DataTemplate(typeof(TextCell))
                {
                    Bindings = { { TextCell.TextProperty, new Binding("Title") },
                        { TextCell.DetailProperty, new Binding("Description") } }
                },
                IsVisible = false
            };
    public class ListViewGroupHeaderCell : ViewCell
        {

        public ListViewGroupHeaderCell()
        {
        this.Height = 32;
        var title = new Label
        {
            FontSize = 16,
            TextColor = Color.Black,
            HorizontalOptions = LayoutOptions.StartAndExpand
        };

        title.SetBinding(Label.TextProperty, "Key");

        Switch switchEnableOrder = new Switch { HorizontalOptions = LayoutOptions.End };
        switchEnableOrder.Toggled += (object sender, ToggledEventArgs e) =>
        {
            if (e.Value)
            {
                //Disable all but this switch here...
            }
            else { }
        };

        StackLayout vwLayoutRight = new StackLayout()
        {
            HorizontalOptions = LayoutOptions.End,
            Orientation = StackOrientation.Vertical,
            Children = { switchEnableOrder }
        };

        View = new StackLayout
        {
            HorizontalOptions = LayoutOptions.FillAndExpand,
            HeightRequest = 32,
            BackgroundColor = Color.Silver,
            Padding = 5,
            Orientation = StackOrientation.Horizontal,
            Children = { title, switchEnableOrder }
        };
     }
}

Could someone show me code how this could be done. Thanks


Viewing all articles
Browse latest Browse all 89864

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>