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

Bind to parent of list in ExpandableListView

$
0
0

I'm trying to create a ExpandableListView. I want to use the property IsVisible inside of the ListView.ItemTemplate so i can show the items or not. The listview is bind to a ObservableCollection _shippingLabels;. How can i bind to the IsVisible?

```c#
public class ShippingLabelHeaderWithLines : ObservableCollection
{
private bool _isVisible;

    public ShippingLabelHeader Header { get; set; }

    public bool IsVisible
    {
        get => _isVisible;
        set => _isVisible = value;
    }

    public bool IconOpen
    {
        get => IsVisible;
    }

    public bool IconClosed
    {
        get => !IsVisible;
    }

    public ShippingLabelHeaderWithLines([NotNull] ObservableCollection<ShippingLabelLine> list, ShippingLabelHeader header) : base(list)
    {
        Header = header;
    }
}```

```xaml


<ListView.GroupHeaderTemplate>



<Grid.RowDefinitions>


</Grid.RowDefinitions>
<Grid.ColumnDefinitions>


</Grid.ColumnDefinitions>

                                        <Button BackgroundColor="White" TextColor="Red" Text="&#xf078;" IsVisible="{Binding IconOpen}"  VerticalOptions="StartAndExpand" Style="{StaticResource FontAwesomeButtonSolid}" Grid.Row="0" Grid.Column="0" HorizontalOptions="StartAndExpand"/>
                                        <Button BackgroundColor="White" TextColor="Red" Text="&#xf054;" IsVisible="{Binding IconClosed}" VerticalOptions="StartAndExpand" Style="{StaticResource FontAwesomeButtonSolid}" Grid.Row="0" Grid.Column="0" HorizontalOptions="StartAndExpand"/>

                                        <Label Text="{Binding Header.No}" FontAttributes="Bold" FontSize="Medium" Grid.Row="0" Grid.Column="1" HorizontalOptions="Fill"/>
                                        <StackLayout Grid.Row="1" Grid.Column="1" Orientation="Horizontal">
                                            <Label Text="&#xf468;" VerticalOptions="Center" Style="{StaticResource FontAwesomeLabelSolid}"/>
                                            <Label Text="{Binding Header.TotalPieces}" FontAttributes="Bold" FontSize="Medium" HorizontalOptions="Fill"/>
                                        </StackLayout>

                                    </Grid>
                                </ViewCell>
                            </DataTemplate>
                        </ListView.GroupHeaderTemplate>
                        <ListView.ItemTemplate>
                            <DataTemplate>
                                <ViewCell>
                                    <Grid Margin="50,5,5,5" IsVisible="{Binding Path=IsVisible, Source={x:Reference LoadAndUnLoad}}">
                                        <Grid.RowDefinitions>
                                            <RowDefinition Height="Auto" />
                                            <RowDefinition Height="Auto" />
                                            <RowDefinition Height="Auto" />
                                        </Grid.RowDefinitions>
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition Width="66*"></ColumnDefinition>
                                            <ColumnDefinition Width="33*"></ColumnDefinition>
                                        </Grid.ColumnDefinitions>

                                        <StackLayout Grid.Row="0" Grid.Column="0" Orientation="Horizontal" >
                                            <Label Text="{Binding Description}" FontSize="Medium" HorizontalOptions="Fill"/>
                                        </StackLayout>
                                        <StackLayout Grid.Row="1" Grid.Column="0" Orientation="Horizontal">
                                            <Label Text="&#xf466;" VerticalOptions="Center" FontSize="Small" Style="{StaticResource FontAwesomeLabelSolid}"/>
                                            <Label Text="{Binding QtyPieces}" FontSize="Medium" HorizontalOptions="Fill"/>
                                        </StackLayout>
                                        <StackLayout Grid.Row="2" Grid.Column="0" Orientation="Horizontal">

                                        </StackLayout>

                                        <StackLayout Grid.Row="0" Grid.Column="1" Orientation="Horizontal">
                                            <Label Text="" FontAttributes="Bold" FontSize="Medium" HorizontalOptions="Fill"/>
                                        </StackLayout>
                                        <StackLayout Grid.Row="1" Grid.Column="1" Orientation="Horizontal">
                                            <Label Text="" FontAttributes="Bold" FontSize="Medium" HorizontalOptions="Fill"/>
                                        </StackLayout>
                                        <StackLayout Grid.Row="2" Grid.Column="1" Orientation="Horizontal"/>
                                    </Grid>
                                </ViewCell>
                            </DataTemplate>
                        </ListView.ItemTemplate>
                    </ListView>

```


Viewing all articles
Browse latest Browse all 77050

Trending Articles



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