piotruspan
piotruspan

Reputation: 219

ImageButton bug in listview(going small on add item)

I made listview with item Template and when i click AddButton and add item to this list imagebuttons in this template going small.

How it shlould look like https://drive.google.com/open?id=1e8BTXzPDhcbhsRO7Jqo7UB08VRfspcaO

How it look like https://drive.google.com/open?id=1fHpveogjKiYLYbZE0WsXhRv9_ah50XMP

My listView:

<ListView x:Name="ThisList" HeightRequest="100" RowHeight="45">
    <ListView.ItemTemplate>
        <DataTemplate>
            <ViewCell>
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="*"/>
                        <ColumnDefinition Width="*"/>
                        <ColumnDefinition Width="40"/>
                    </Grid.ColumnDefinitions>
                    <TimePicker  Grid.Column="0" HorizontalOptions="Center" FontFamily="{StaticResource MTBfont}" Time="{Binding time}"/>
                    <ImageButton Source="{Binding img}" Grid.Column="1" HorizontalOptions="Center" BackgroundColor="Transparent" Clicked="ProfileD_Clicked"/>
                    <ImageButton IsVisible="{Binding visible}" Source="deleteicon.png" Grid.Column="2" MinimumWidthRequest="30" WidthRequest="30" HorizontalOptions="Center"  BackgroundColor="Transparent" Clicked="DeleteD_Clicked"/>``
                </Grid>
            </ViewCell>
        </DataTemplate>
    </ListView.ItemTemplate>
    <ListView.Footer>
        <ImageButton Clicked="AddDButton_Clicked" Source="button_add.png" WidthRequest="50" VerticalOptions="Center" HorizontalOptions="Center" BackgroundColor="Transparent"/>
    </ListView.Footer>
</ListView>

My Code of add button:

private void AddDButton_Clicked(object sender, EventArgs e)
{
     ItemD.Add(new SchamatListItem(){
        img = "eco.png",
        time = ItemD[ItemD.Count() - 1].time + TimeSpan.FromHours(1),
        visible = true,
        index = counterD
     });
     counterD++;
     ThisList.HeightRequest = ThisList.HeightRequest + 45;
}

MY SOLUTION I think it's not the best but it works.

<Image IsVisible="{Binding visible}" Source="deleteicon.png" Grid.Column="2" MinimumWidthRequest="30" WidthRequest="30" HorizontalOptions="Center"  BackgroundColor="Transparent">
                                                    <Image.GestureRecognizers>
                                                        <TapGestureRecognizer Tapped="DeleteD_Clicked" NumberOfTapsRequired="1"/>
                                                    </Image.GestureRecognizers>
                                                </Image>

Upvotes: 1

Views: 309

Answers (3)

piotruspan
piotruspan

Reputation: 219

MY SOLUTION I think it's not the best but it works.

<Image IsVisible="{Binding visible}" Source="deleteicon.png" Grid.Column="2" MinimumWidthRequest="30" WidthRequest="30" HorizontalOptions="Center"  BackgroundColor="Transparent">
                                                    <Image.GestureRecognizers>
                                                        <TapGestureRecognizer Tapped="DeleteD_Clicked" NumberOfTapsRequired="1"/>
                                                    </Image.GestureRecognizers>
                                                </Image>

Upvotes: 0

return0
return0

Reputation: 103

Try removing the background color property from image button. Its an existing bug -https://github.com/xamarin/Xamarin.Forms/issues/4510

Upvotes: 1

AndreaGobs
AndreaGobs

Reputation: 386

You can also set the VerticalOptions of the ImageButtons to Fill adding Aspect to AspectFit, and eventually adding a margin, as below:

Upvotes: 0

Related Questions