Reputation: 101
I have been having some issues resizing my list view row to match the text inside of it. Also I have read a lot of documentation and everything seems to point toward using HasUnevenRows
, which I am using but isn't quite what I need.
I have a ListView
which I allow the user to modify contents of this row using Rg.Popups
and context actions. Essentially the user swipes and clicks Edit and they get pushed to a popup where they can edit the list view item.
When the note gets updated it also gets updated on my ListView
however if the note is more than 1 line the row will not resize. I have to leave the page and come back to it for the row to resize to fit the entire note.
Below is my code.
<ListView x:Name="MyItemList"
HorizontalOptions="Center"
ItemSelected="OpenRecipeDetails"
IsGroupingEnabled="True"
HasUnevenRows="true">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell x:Name="myViewcell">
<ViewCell.ContextActions>
<MenuItem Clicked="MenuItem_Clicked" Text="Edit Note" CommandParameter="{Binding .}"/>
</ViewCell.ContextActions>
<StackLayout>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Label Text="{Binding Title}"
Grid.Row="0"
Grid.Column="0"
FontSize="{Binding BindingContext.H1Font, Source={x:Reference Name=ThisPage}}"
Padding="5"
LineBreakMode="WordWrap">
</Label>
<Label Text="{Binding sNote}"
Grid.Row="1"
Grid.Column="0"
FontSize="{Binding BindingContext.H2Font, Source={x:Reference Name=ThisPage}}"
>
</Label>
</Grid>
<!-- -->
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
CodeBehind
//for editing the note
async void MenuItem_Clicked(System.Object sender, System.EventArgs e)
{
var menuItem = sender as MenuItem;
updatedItem = menuItem.CommandParameter as MyItemBooklet;
await PopupNavigation.Instance.PushAsync(new EditNotesPopupPage(updatedItem));
}
EditNotesPopupPage
public EditNotesPopupPage( MyItemBooklet item)
{
InitializeComponent();
_item = item;
}
...
async void Cancel_Clicked(System.Object sender, System.EventArgs e)
{
await PopupNavigation.Instance.PopAllAsync();
}
async void Ok_Clicked(System.Object sender, System.EventArgs e)
{
...
...
await db.UpdateNote(text, _item.iRecipeLinkID);
await PopupNavigation.Instance.PopAllAsync();
}
Upvotes: 1
Views: 1144
Reputation: 472
You can try force update size of ViewCell below is the link with good sample that will guide you:
Upvotes: 1