BindablePicker inside Multi-select ListView (per row)

k1dw0lfk1dw0lf UYMember ✭✭

Hello everyone.

My problem is that I'm working with multi-select and I need a bindablepicker inside with a binding list from the view model. I can't make it work and I'm really stuck, has anyone find a solution for this?

Answers

  • JulienRosenJulienRosen CAMember ✭✭✭✭

    what have you tried?

    show some code

  • k1dw0lfk1dw0lf UYMember ✭✭

    I've tried to edit the Multi-select listview control by adding a picker...
    Here is some code:

                      public class MultipleSelectCell : ViewCell
                          {
                            public static readonly BindableProperty NameProperty = BindableProperty.Create("Name", typeof(string), typeof(MultipleSelectCell), "");
                     public static readonly BindableProperty ItemsSourceProperty = BindableProperty.Create("ItemsSource", typeof(IEnumerable), typeof(MultipleSelectCell), null);
    
                            public string Name
                            {
                                get { return (string)GetValue(NamePrope``rty); }
                                set { SetValue(NameProperty, value); }
                            }
    
                              public IList ItemsSource
                              {
                                  get { return (IList)base.GetValue(Picker.ItemsSourceProperty); }
                                  set { base.SetValue(Picker.ItemsSourceProperty, value); }
                              }
                ....... ......
                            Grid infoLayout = new Grid
                                     {
                                         ColumnDefinitions =
                                         {
                                             new ColumnDefinition { Width = new GridLength(1,GridUnitType.Star) },
                                             new ColumnDefinition { Width = new GridLength(1,GridUnitType.Star) },
                                         },
                                         HorizontalOptions = LayoutOptions.FillAndExpand
                                     };
                                     infoLayout.Children.Add(lbName, 0, 0);
                                     infoLayout.Children.Add(picker, 0, 1);
            ........    .......
                        protected override void OnBindingContextChanged()
            {
                base.OnBindingContextChanged();
    
                if (BindingContext != null)
                {
                    lbName.Text = Name;
                    picker.ItemsSource = ItemsSource;
                    picker.SelectedIndex = 0;
                }
            }
    

    In xaml:

            <ListView Grid.Column="2" Grid.Row="1" HasUnevenRows="false" x:Name="lstRisks" ItemsSource="{Binding Risks}">
                                        <ListView.ItemTemplate>
                                            <DataTemplate>
                                            <custom:MultipleSelectCell Name="{Binding Item.Description}" ItemsSource="{Binding Source={x:Static viewModels:AreasViewModel.CriticityLevels}"  />
                                            </DataTemplate>
                                        </ListView.ItemTemplate>
                                    </ListView>
    

    Te multipleselect is drawing the picker but I just cant fill the itemsource, i want to fill it from a list in the viewModel and not from a attribute from Risks List that u can see in the ItemsSource from the ListView.

  • JulienRosenJulienRosen CAMember ✭✭✭✭
    edited September 2017

    the BindingContext of your ItemTemplate is already an individual item from your ItemsSource. You don't need to create attached properties to feed in the data, you can just bind directly from the cell.

    I'd highly recommend creating your template in XAML, c# is pretty horrid for layout.

  • k1dw0lfk1dw0lf UYMember ✭✭

    I just made it by using the ItemSource property from the Picker, adding this line: picker.SetBinding(Picker.ItemsSourceProperty, "ItemSource");

    Then I bind the Picker in the ViewModel using the property that I made in SelectableItemWrapper that is the class that the control MultiSelect has..
    Sorry about my english and I'm really newbie at Xamarin xD..

    Thank u..

Sign In or Register to comment.