0

I have CarouselView that has a Dictionary<string,ObservableCollection as its itemssource.

A Control is created for each string in the dictionary's keys. The Control takes in a viewmodel for the constructor.

I want to pass in the current key as a string for the constructor's argument of the view model being created. Is this possible to do with XAML and .Net MAUI?

I have tried several ways and I need to know if it is even possible.

Thank you.

Here is the XAML code


  <CarouselView  x:Name="lstModifierLists" x:DataType="local:SelectedItemViewModel" ItemsSource="{Binding OrderMenuItem.MenuModifierListNames.Keys}">
            <CarouselView.ItemTemplate>
                <DataTemplate>
                    <inclmod:ItemModiferCollectionControl BackgroundColor="AliceBlue" >                        
                        <x:Arguments>
                            <local:ItemModifierCollectionControlViewModel>
                                **<x:Arguments>
                                    // I want to pass in the current item or Key of lstModifierLists Here
                                </x:Arguments>
**                            </local:ItemModifierCollectionControlViewModel>
                        </x:Arguments>
                    </inclmod:ItemModiferCollectionControl>
                </DataTemplate>
            </CarouselView.ItemTemplate>
        </CarouselView>
Clay H
  • 1
  • 1

1 Answers1

0

The Arguments in XAML can be used to pass arguments to non-default constructors, to call factory methods, and to specify the type of a generic argument.

You can not pass the data to the arguments. But you can use the static data to make Generics in Xamarin.Forms XAML

Guangyu Bai - MSFT
  • 2,555
  • 1
  • 2
  • 8