Отрегулируйте высоту списка в зависимости от его содержимого внутри сетки в формах xamarin - PullRequest
0 голосов
/ 14 сентября 2018

У меня есть сетка во всплывающем окне с тремя строками (поиск, просмотр списка и кнопка). Мне нужно настроить высоту списка в зависимости от количества элементов внутри списка.

Вот страница макета:

<pages:PopupPage xmlns="http://xamarin.com/schemas/2014/forms"
         xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
         xmlns:pages="clr-namespace:Rg.Plugins.Popup.Pages;assembly=Rg.Plugins.Popup"
             xmlns:animations="clr-namespace:Rg.Plugins.Popup.Animations;assembly=Rg.Plugins.Popup"
         x:Class="TCRMobile.Pages.Popups.CustomerContactsListPopup">
<pages:PopupPage.Animation>
    <animations:ScaleAnimation 
  PositionIn="Center"
  PositionOut="Center"
  ScaleIn="1.2"
  ScaleOut="0.8"
  DurationIn="100"
  DurationOut="100"
  EasingIn="SinIn"
  EasingOut="SinOut"
  HasBackgroundAnimation="True"/>
</pages:PopupPage.Animation>
<pages:PopupPage.Content>
    <StackLayout VerticalOptions="Center" HorizontalOptions="FillAndExpand" Margin="20" Padding="20, 20, 20, 20" BackgroundColor="White" Orientation="Vertical">
        <Label Text="Select Name" HorizontalOptions="StartAndExpand" FontSize="20" TextColor="Black"></Label>
        <Grid VerticalOptions="FillAndExpand">
            <Grid.RowDefinitions>
                <RowDefinition Height="1*"></RowDefinition>
                <RowDefinition Height="Auto"></RowDefinition>
                <RowDefinition Height="1*"></RowDefinition>
            </Grid.RowDefinitions>
            <SearchBar Grid.Row="0" HorizontalOptions="FillAndExpand"  Placeholder="Search" PlaceholderColor="Gray" 
                       x:Name="searchItem" TextChanged="searchItem_TextChanged"></SearchBar>
            <ListView Grid.Row="1" x:Name="lvContacts" CachingStrategy="RecycleElement" HasUnevenRows="True" SeparatorVisibility="None"
                  ItemTapped="lvContacts_ItemTapped">
                <ListView.ItemTemplate>
                    <DataTemplate>
                        <ViewCell>
                            <Grid Margin="5">
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="Auto"></RowDefinition>
                                </Grid.RowDefinitions>
                                <Label Grid.Row="0" Text="{Binding Name}" TextColor="Black" HorizontalOptions="FillAndExpand" VerticalOptions="CenterAndExpand" ></Label>
                            </Grid>
                        </ViewCell>
                    </DataTemplate>
                </ListView.ItemTemplate>
            </ListView>

                <Button Grid.Row="2" Text="Enter Name" TextColor="White" BackgroundColor="#8BC34A" Margin="80,0,80,0" Command="{Binding EnterNameButtonCommand}" ></Button>
        </Grid>

    </StackLayout>

Мой код файла .cs выглядит следующим образом:

 VM = new CustomerContactsListViewModel(this);
        this.BindingContext = VM;
        lvContacts.ItemsSource = VM.customerContacts;
        int i = VM.customerContacts.Count;
        int heightrowList = 40;
        i = (VM.customerContacts.Count * heightrowList);
        lvContacts.HeightRequest = i;

Приведенный выше код работает по-разному с другим значением heightrowList.

Любая помощь?

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...