0
votes

I want to use just 1 list view for my ContentPage. The problem is that I need to bind two different types of data from an object list.

I tried to set the bind from code but is working for just 1 list elements

The first ItemSource is the one that is binding the elements.

The second one contains different data but I want to use the same XAML code to display it.

In the xaml part, lets say I can/want reuse: {Binding sRFC} and {Binding sNombre}

PickLista.ItemsSource = lst; // Bound list correctly - this is in code

PickLista.ItemsSource = ls; // List 2 with other object elements - this is in code


           <ListView x:Name="myLista" HasUnevenRows="true" Margin="5" SelectionMode="None">
            <ListView.ItemTemplate>
                <DataTemplate>
                    <ViewCell>
                        <StackLayout Orientation="Horizontal" Spacing="5"  HeightRequest="40" >
                            <Label Text="{Binding iId}" VerticalTextAlignment="Start" HorizontalTextAlignment="Start" TextColor="Black" FontSize="15"/>
                            <Label Text="{Binding sRFC}" VerticalTextAlignment="Start" HorizontalTextAlignment="Start" TextColor="Black" FontSize="15"/>
                            <Label Text="{Binding sNombre}" VerticalTextAlignment="Start" HorizontalTextAlignment="Start" TextColor="Black" FontSize="15"/>
                        </StackLayout>
                    </ViewCell>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>

I want to be able to display both object elements in the same list view, or if i can use another listview in the same position over the other (via XAML).

1
You want to change the ItemsSource at runtime to toggle between two different sets of data?Jason
Exactly, I change data at runtimeCarlos Aldair Orta
And both Lists are of a type that contain the relevant properties? I'd expect this to work, but it might be better to use two lists and just toggle their IsVisible as neededJason
In a stacklayout, that property is going to give the space of list 1 to list 2 ? or you recommend other layout ? to put the two listviews in the same positionCarlos Aldair Orta
do you want to switch between two lists ? or you want a list contains two different types of data at the same time ?Leo Zhu - MSFT

1 Answers

0
votes

If those properties are named the same in both classes and satisfy everything required for binding it will work. So either you have different name or properties in some class are not public or don't have getters...