I have code like this:
You can achieve this following the guide provided by the xamarin forms developers site at https://developer.xamarin.com/guides/xamarin-forms/user-interface/layouts/custom/
The problem you described is exactally what the sample code this guide shows. Creating a custom layout you can reuse this solution everywhere you need it.
Succinctly, what you have to do to create your WrapLayout:
You may get results like this: