Hi guys,
I have a content page that contains a list view and a stack layout under it (called BottomLayout
in the code). This stack layout contains an CustomEditor
and a button, displayed horizontally. In order for the CustomEditor
to grow together with the content, I have defined it in the following way, as suggested in other posts on this forum:
public class CustomEditor : Editor
{
public CustomEditor()
{
TextChanged += (sender, e) => InvalidateMeasure();
}
}
This solution works pretty well when expanding, and allows also shrinking when deleting text. The only issue is that it grows vertically in the up direction until it covers most of the list view, then it continues growing again, but this time in the down direction, so it goes "under" the bottom of the screen. In this case the preferred behaviour would be for the Editor to stop growing, and allow scrolling. In order to do so, I am setting a height request on the editor when the height is bigger than a certain value (350 in the example). This is more or less my code:
MyPage()
{
myListView = new CustomListView(ListViewCachingStrategy.RecycleElement)
{
VerticalOptions = LayoutOptions.FillAndExpand,
HorizontalOptions = LayoutOptions.FillAndExpand,
...
};
myEditor = new CustomEditor()
{
HorizontalOptions = LayoutOptions.FillAndExpand,
VerticalOptions = LayoutOptions.Start,
};
myButton = new Button
{
HorizontalOptions = LayoutOptions.End,
VerticalOptions = LayoutOptions.Start,
};
BottomLayout = new StackLayout
{
Orientation = StackOrientation.Horizontal,
HorizontalOptions = LayoutOptions.FillAndExpand,
VerticalOptions = LayoutOptions.End,
Children =
{
myEditor,
myButton,
},
};
BottomLayout.LayoutChanged += BottomLayout_LayoutChanged;
ListLayout = new StackLayout
{
Orientation = StackOrientation.Vertical,
HorizontalOptions = LayoutOptions.FillAndExpand,
VerticalOptions = LayoutOptions.FillAndExpand,
Children =
{
myListView
},
};
Content = new StackLayout
{
Orientation = StackOrientation.Vertical,
Children =
{
ListLayout,
BottomLayout,
},
};
}
void BottomLayout_LayoutChanged(object sender, EventArgs e)
{
if (myEditor.Height > 350)
{
myEditor.HeightRequest = 350;
}
}
When the editor grows higher than 350, the height is fixed, and it starts scrolling, as it should be. The problem is that now the editor does not shrink anymore, even when the text occupies only one line. Do you have any suggestions regarding how to deal with this issue?