Xamarin Portable Comments Stacklayout height problems Listview

I am having trouble with height problems in Xamarin PCL with Listview. I want to create a comments section in a scrollable page. But i am struggling with the height of the comments. It just wont expand.

Row.Definition = Auto for the Grid:

            <StackLayout Grid.Row="4" Padding="0,20,0,0">
                <ListView ItemsSource="{Binding CommentsMVVM}" HasUnevenRows="True">
                    <ListView.ItemTemplate>
                        <DataTemplate>
                            <ViewCell>
                                <local:CommentsRow />
                            </ViewCell>
                        </DataTemplate>
                    </ListView.ItemTemplate>
                </ListView>
            </StackLayout>

In the CommentsRow template:

<Grid RowSpacing="0" ColumnSpacing="14" Padding="20" VerticalOptions="FillAndExpand">

    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="Auto" />
        <ColumnDefinition Width="*" />
    </Grid.ColumnDefinitions>

    <Grid.RowDefinitions>
        <RowDefinition Height="Auto" />
        <RowDefinition Height="Auto" />
        <RowDefinition Height="*" />
    </Grid.RowDefinitions>

    <Image Grid.Column="0" Grid.RowSpan="3" Source="{ Binding Image }" VerticalOptions="Start" />

    <Label Grid.Column="1" Grid.Row="0" Text="{ Binding UserName }" VerticalOptions="EndAndExpand" TextColor="Blue" />

    <Label Grid.Column="1" Grid.Row="1" Margin="0,4,0,0" Text="{ Binding CreatedAt }" TextColor="Grey" FontSize="13" />

    <StackLayout Grid.Column="1" Grid.Row="2" Spacing="30" x:Name="StackLayoutMap"  VerticalOptions="FillAndExpand" />



</Grid>

And at the C#:

    public CommentsRow()
    {

        InitializeComponent();

        var html_label = new HtmlFormattedLabel()
        {
            TextColor = Color.Black,
            FontSize = Device.GetNamedSize(NamedSize.Small, typeof(Label)),
        };


        html_label.SetBinding(HtmlFormattedLabel.TextProperty, "Memo");

        this.StackLayoutMap.Children.Add(html_label);



    }

But the StackLayout comments text just wont expand automatically. What am i doing wrong?

Answers

  • ClintStLaurentClintStLaurent USUniversity ✭✭✭✭✭

    Just as a test...
    What if you don't add the comment later in C#? If you include it in your XAML does it behave?
    If that works, then instead of adding it in code behind you might be able to leave it in place in the XAML and just toggle its IsVisible property when you need to hide it.

  • FaithFaithFaithFaith USMember ✭✭

    It does not work. I have tried everything.

  • ClintStLaurentClintStLaurent USUniversity ✭✭✭✭✭

    If you can start a new 'Welcome to Xamarin' solution, and reproduce it... submit that solution as part of a bug report on bugzilla.

    From experience, if you can hand them a basic solution where it is easy to reproduce it will get low priority. Which is common sense since they have to do more work, take more time and thus it is more expensive to handle reported bugs that don't include a reproduction solution.

  • FaithFaithFaithFaith USMember ✭✭
    edited November 2017

    If i Change the:

                <Grid.RowDefinitions>
                    <RowDefinition Height="125" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="40" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                </Grid.RowDefinitions>
    

    Into:

                <Grid.RowDefinitions>
                    <RowDefinition Height="125" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="40" />
                    <RowDefinition Height="1500" />
                    <RowDefinition Height="Auto" />
                </Grid.RowDefinitions>
    

    The listview does expand like it should

  • ClintStLaurentClintStLaurent USUniversity ✭✭✭✭✭
    edited November 2017

    I don't see the difference between the two

    Edit: Those numbers really don't translate well to other screen resolutions though, do they. A phone, a tablet, and AppleTV on a 1920x1080 monitor.... Normally I try to avoid such hard values and stick with relative terms.

    <Grid.RowDefinitions>
                    <RowDefinition Height="3*" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="1*" />
                    <RowDefinition Height="30*" />
                    <RowDefinition Height="Auto" />
                </Grid.RowDefinitions>
    
  • FaithFaithFaithFaith USMember ✭✭

    I was just testing if the ListView is doing his job.

  • FaithFaithFaithFaith USMember ✭✭

    I am using the HtmlFormattedLabel for the HTML comments. But when we use smiles that should be on a URL it won't show up in the HTMLFormattedLabel. Is there another solution?

Sign In or Register to comment.