Hi I want to auto size scroll view to fit its content. It should scroll till the end of list view in all devices in landscape mode. Right now my issue is that I have to keep changing the Height of scroll view according to the device and it is not proper. This is is my code behind.
if (svMainBody.Children.Contains(grdListBody))
{
svMainBody.Children.Remove(grdListBody);
svMain = new ScrollView { Content = grdListBody };
svMainBody.Children.Add(svMain);
}
else
{
svMainBody.Children.Add(svMain);
}
rdListViewHeight.Height = height * 0.30;
}
}
else
{
if (IsPortrait(this))
{
//Fix for scrolling only listview in portrait
if (svMainBody.Children.Contains(svMain))
{
svMainBody.Children.Remove(svMain);
svMainBody.Children.Add(grdListBody);
}
else
{
svMainBody.Children.Add(grdListBody);
}
if (Settings.Flowsheet.sl1 == "")
Settings.Flowsheet.sl1 = sl1.Height.ToString();
dstk1Height = Settings.Flowsheet.sl1 == "" ? sl1.Height : Convert.ToDouble(Settings.Flowsheet.sl1);
if (Device.RuntimePlatform == Device.Android)
rdListViewHeight.Height = height - 160 - sl1.Height - 40;
else
rdListViewHeight.Height = height - 160 - dstk1Height - 30;
}
else
{
//Fix for scrolling entire page in landscape
if (svMainBody.Children.Contains(grdListBody))
{
svMainBody.Children.Remove(grdListBody);
svMain = new ScrollView { Content = grdListBody };
svMainBody.Children.Add(svMain);
}
else
{
svMainBody.Children.Add(svMain);
}
rdListViewHeight.Height = height * 3.0;
}
And this is my xaml codes
<StackLayout x:Name="svMainBody" Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="13" VerticalOptions="FillAndExpand">
<Grid x:Name="grdListBody" Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="13" BackgroundColor="#EEEEEE" VerticalOptions="FillAndExpand">
<Grid.RowSpacing>0</Grid.RowSpacing>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition x:Name="rdListViewHeight" Height="Auto"></RowDefinition>
</Grid.RowDefinitions>
<StackLayout Padding="10,10,10,10" Grid.Row="0" x:Name="sl1" VerticalOptions="Start">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"></ColumnDefinition>
<ColumnDefinition Width="40"></ColumnDefinition>
<ColumnDefinition Width="*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Label Grid.Row="0" Grid.Column="0" x:Name="lblSetTime" Text="{Binding SetTime}" TextColor="Black" HorizontalOptions="Start"></Label>
<Label Grid.Row="0" Grid.Column="1" x:Name="lblMeetingRoom" Grid.ColumnSpan="2" Text="{Binding MeetingRoom}" TextColor="Black" HorizontalOptions="Start"></Label>
<Label Grid.Row="1" Grid.Column="0" x:Name="lblSetByStrikeBy" Text="{Binding SetByStrikeBy}" TextColor="Black" HorizontalOptions="Start" IsVisible="{Binding IsVisibleLblSetByStrikeBy}"></Label>
<Label Grid.Row="1" Grid.Column="1" x:Name="lblRoomSetter" Grid.ColumnSpan="2" Text="{Binding RoomSetter}" TextColor="Black" HorizontalOptions="Start" IsVisible="{Binding IsVisibleLblRoomSetter}"></Label>
<Label Grid.Row="2" Grid.Column="0" x:Name="lblStartTime" Text="{Binding StartTime}" TextColor="Black" HorizontalOptions="Start"></Label>
<Image Grid.Row="2" Grid.Column="1" x:Name="imgPromoterScore" Source="" HeightRequest="20" WidthRequest="20" HorizontalOptions="Start" IsVisible="False" ></Image>
<Label Grid.Row="2" Grid.Column="1" Grid.ColumnSpan="2" x:Name="lblClientCompany" Text="{Binding ClientCompany}" TextColor="Black" HorizontalOptions="Start"></Label>
<Label Grid.Row="3" Grid.Column="0" x:Name="lblEndTime" Text="{Binding EndTime}" TextColor="Black" HorizontalOptions="Start"></Label>
<Image Grid.Row="3" Grid.Column="1" x:Name="imgPlannerScore" Source="" HeightRequest="20" WidthRequest="20" HorizontalOptions="Start" IsVisible="False"></Image>
<Label Grid.Row="3" Grid.Column="1" Grid.ColumnSpan="2" x:Name="lblClientPlanner" Text="{Binding ClientPlanner}" TextColor="Black" HorizontalOptions="Start"></Label>
<Label Grid.Row="4" Grid.Column="0" x:Name="lblStrikeTime" Text="{Binding StrikeTime}" TextColor="Black" HorizontalOptions="Start"></Label>
<Label Grid.Row="4" Grid.Column="1" x:Name="lblPostAs" Grid.ColumnSpan="2" Text="{Binding PostAs}" TextColor="Black" HorizontalOptions="Start"></Label>
<Label Grid.Row="5" Grid.Column="0" x:Name="lblAction" Text="{Binding Action}" TextColor="Black" HorizontalOptions="Start"></Label>
<Label Grid.Row="5" Grid.Column="1" x:Name="lblVenuePlanner_PSAVSalesPerson" Grid.ColumnSpan="2" Text="{Binding VennuePlanner_PSAVSalesPerson}" TextColor="Black" HorizontalOptions="Start"></Label>
</Grid>
</StackLayout>
<StackLayout Grid.Row="1" VerticalOptions="FillAndExpand" Orientation="Vertical">
<BoxView BackgroundColor="Black" HeightRequest="1" HorizontalOptions="FillAndExpand"/>
<StackLayout Padding="10,5,10,5" Orientation="Vertical" BackgroundColor="#EEEEEE" x:Name="sl2" VerticalOptions="FillAndExpand">
<local1:CustomListviewEventDetails
x:Name="lstItems" HasUnevenRows="True" SeparatorVisibility="None" BackgroundColor="#EEEEEE" ItemsSource="{Binding lstViewItemSource}" ItemSelected="lstItems_ItemSelected" VerticalOptions="FillAndExpand"
IsGroupingEnabled="True">
<local1:CustomListviewEventDetails.GroupHeaderTemplate>
<DataTemplate>
<local1:CustomViewCellFS>
<StackLayout HorizontalOptions="FillAndExpand" >
<!--Padding="20,0,0,0" VerticalOptions="CenterAndExpand"-->
<!--HorizontalOptions="CenterAndExpand"-->
<Label Text="{Binding SectionName}" FontSize="15" FontAttributes="Bold" TextColor="White" VerticalOptions="CenterAndExpand" VerticalTextAlignment="Center" XAlign="Center" />
</StackLayout>
</local1:CustomViewCellFS>
</DataTemplate>
</local1:CustomListviewEventDetails.GroupHeaderTemplate>
<local1:CustomListviewEventDetails.ItemTemplate>
<DataTemplate>
<ViewCell>
<ViewCell.View>
<StackLayout Padding="0,0,0,0">
<Grid RowSpacing="0">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="5"></RowDefinition>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="0.1*"></ColumnDefinition>
<ColumnDefinition Width="0.9*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<!--Label Grid.Row="0" Grid.ColumnSpan="2" Text="{Binding SectionName}" FontSize="15" TextColor="Black" HorizontalOptions="C
enterAndExpand"></Label>-->
<!--<Label Grid.Row="1" Grid.ColumnSpan="2" Text="{Binding PackageName}" FontSize="15" TextColor="Black" HorizontalOptions="StartAndExpand"></Label>
-->
<Label Grid.Row="0" Grid.Column="0" Text="{Binding PackageQuantity}" FontSize="15" TextColor="Black" HorizontalOptions="Start" IsVisible="{Binding PackageNameVisibility}" FontAttributes="Bold" >
</Label>
<Label Grid.Row="0" Grid.Column ="1" Text="{Binding PackageName}" FontSize="15" TextColor="Black" HorizontalOptions="Start" HorizontalTextAlignment="Start" IsVisible="{Binding PackageNameVisibility}" FontAttributes="Bold" ></Label>
<Label Grid.Row="1" Grid.Column="0" Text="{Binding Quantity}" FontSize="15" TextColor="Black" HorizontalOptions="Start" HorizontalTextAlignment="Start" >
</Label>
<Label Grid.Row="1" Grid.Column="1" Text="{Binding Item}" FontSize="15" TextColor="Black" HorizontalOptions="StartAndExpand" HorizontalTextAlignment="Start" Margin="{Binding MargProp}" >
</Label>
<!--<Label Grid.Row="2" Grid.Column="0" Text="{Binding SectionQuantity}" FontSize="15" TextColor="Black" HorizontalOptions="Start" HorizontalTextAlignment="Start" IsVisible="{Binding SectionItemVisibility}" >
</Label>
<Label Grid.Row="2" Grid.Column="1" Text="{Binding SectionItem}" FontSize="15" TextColor="Black" HorizontalOptions="StartAndExpand" HorizontalTextAlignment="Start" IsVisible="{Binding SectionItemVisibility}" >
</Label>-->
<BoxView x:Name="txt" Grid.Row="3" Grid.ColumnSpan="2" HeightRequest="5" ></BoxView>
</Grid>
</StackLayout>
</ViewCell.View>
</ViewCell>
</DataTemplate>
</local1:CustomListviewEventDetails.ItemTemplate>
</local1:CustomListviewEventDetails>
</StackLayout>
</StackLayout>
</Grid>
</StackLayout>
I'm setting the height as 3.0 but i want the height to be Auto.
I have fixed the issue by specifying
rdListViewHeight.Height = Content.Height;
Instead of
rdListViewHeight.Height = height * 3.0;