Open neoleptic opened 5 years ago
In this case there are a few things to be aware of, and a few tricks that will improve performance. View creation is an expensive operation on all platforms, but particularly Android.
ItemsControl
is not virtualizing, and ComboBox
currently isn't virtualizing on Android (#556), so these should not be your first choice for showing large numbers of items.ListView
and GridView
: if the style for these controls is customised (ie the style for the control itself, not for item containers), the ScrollViewer
inside the template needs to have xamarin:Style="{StaticResource ListViewBaseScrollViewerStyle}"
as explained here.ListViewItem
style used by Uno is quite heavy (since ListViewItemPresenter
isn't yet supported). Using a lightweight container template style will reduce the number of views created and directly improve page load time. You can find a working example here.Came across this issue in one of the projects I'm working on. Switching the ScrollView style as suggested solved the problem.
I applied this style:
<xamarin:Style TargetType="ScrollViewer"
x:Key="ListViewBaseScrollViewerStyle">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ScrollViewer">
<xamarin:ListViewBaseScrollContentPresenter x:Name="ScrollContentPresenter"
Content="{TemplateBinding Content}"
ContentTemplate="{TemplateBinding ContentTemplate}"
ContentTemplateSelector="{TemplateBinding ContentTemplateSelector}" />
</ControlTemplate>
</Setter.Value>
</Setter>
</xamarin:Style>
@DanielCauser how do i implement your code? Sorry im new on uno plataform.
@pitush Can you open a discussion with the behavior you're getting? Also make sure to read our performance tips documentation first.
We choose Uno (over plain Xamarin because of the Xaml-Support) for porting our Apps to Android. So far, Uno seems quiet promising. Although, while testing the MvvmLight and Control capabilities in a relatively simple Application, I discovered some Performance-Issues while Self-Knowing Collection-Controls are rendered. It first occured when using a ListView with an ItemsSource bound to the ViewModel, but I tried different approaches, a one-column GridView, a Combobox as well as a ContentControl, and except the ContentControl (which has no Selection-Capabilities) any Navigation to the page containing these Controlls took at least 3 Seconds (this was tested with a Nokia 3 [MediaTek MT6737] with Android 8.1), and aproximately another second for every Collection-Control added to the page. There are no noteworthy differences, when adding Items directly in Xaml, instead of binding to the ViewModel.
This is the related View
And its ViewModel
Binding works via a simple ViewModelLocator
Attatched to the DataContext in CodeBehind
And registered in App.xaml.cs - OnLaunched
We understand the device we are using is not the newest or best, our App is B2B so the users usualy use faster devices. Still, it would be great, if this specific lack in performance could be solved any how, or at least to know, we need to incorporate this issue, when recomending devices to our customers.