Navi Mumbai Call Girls Service Pooja 9892124323 Real Russian Girls Looking Mo...
Hà nội – xamarin tech talk
1. Hà Nội – Xamarin Tech Talk
1. Xamarin Forms – Layout Performance
2. ListView scroll performance
2. DO AND DON’T IN XAMARIN FORMS LAYOUT
1. DO enable XAML compilation if you’re using XAML:
[assembly: XamlCompilation(XamlCompilationOptions.Compile)]
2. DO NOT assign default values. Doing so has a cost even though
you’re not modifying the value.
Ex: don’t assign HorizontalOption or VerticalOption to
FillAndExpand (it’s default value)
3. DO use async/await to avoid blocking the main thread
3. DO AND DON’T IN XAMARIN FORMS LAYOUT
4. MessegingCenter
• Be particularly careful if you’re using MessagingCenter in your view’s constructor
because it will not marshal the event to the correct thread for you.
• Shouldn’t use closure/lambda expression (anonymus function) for subcription is easy
way to leak memory, should use method for it
//Subscibe to insert expenses
MessagingCenter.Subscribe<YourClassModel>(this, "AddNew", (expense) => { //some things
todo here });
//Subscibe to insert expenses
MessagingCenter.Subscribe<YourClassModel>(this, "AddNew", this.AddNewSubcription);
private void AddNewSubcription(YourClassModel expense)
{
//some things todo here
}
4. DO AND DON’T IN XAMARIN FORMS LAYOUT
5. Layout
• DO NOT use a ContentView with Padding just to apply a margin to the child.
Instead, use the Margin property on the child
• DO NOT use a StackLayout to host a single child.
• DO NOT use a Grid when a StackLayout suffices.
• PREFER the VerticalTextAlignment and HorizontalTextAlignment properties of
Label over VerticalOptions and HorizontalOptions
• DO NOT use multiple Labels when one will do (using spans with
FormattedText if necessary)
5. DO AND DON’T IN XAMARIN FORMS LAYOUT
• DO be aware of the Spacing (ColumnSpacing/RowSpacing for Grid)
and Padding properties
6. DO AND DON’T IN XAMARIN FORMS LAYOUT
6. Who write UI by C#
• DO pack children into the view before parents
• DO pack views in your constructor rather than OnAppearing
• DO NOT call Layout() (and especially ForceLayout())
• DO NOT use a StackLayout inside a ScrollView to simulate a ListView
• Try use AbsoluteLayout and try not to use RelativeLayout at all
7. DO AND DON’T IN XAMARIN FORMS LAYOUT
8. ListView
• DO NOT put a ListView inside a ScrollView. Use the ListViews Header and
Footer properties instead
• DO NOT use TableView where you can use a ListView. Today, the only real
reason to use a TableView is for settings-style UI where pretty much every cell
has unique content
• DO use ListViewCachingStrategy.RecycleElement. ListView have two caching
mechanism: RecycleElement and RetainElement.
8. RetainElement: The RetainElement value specifies that the ListView will
generate a cell for each item in the list. It should generally be used in the
following circumstances:
• When each cell has a large number of bindings (20-30+).
• When the cell template changes frequently.
• When testing reveals that the RecycleElement value results in a reduced execution
speed.
It's important to recognize the consequences of the RetainElement value when
working with custom cells. Any cell initialization code will need to run for each
cell creation, which may be multiple times per second. In this circumstance,
layout techniques that were fine on a page, like using multiple nested
StackLayout instances, become performance bottlenecks when they are setup
and destroyed in real time as the user scrolls.
RecycleElement: The RecycleElement value specifies that the ListView will
attempt to minimize its memory footprint and execution speed by recycling list
cells. This mode does not always offer a performance improvement, and testing
should be performed to determine any improvements. However, it is generally
the preferred choice, and should be used in the following circumstances:
9. • When each cell has a small to moderate number of bindings.
• When each cell's BindingContext defines all of the cell data.
• When each cell is largely similar, with the cell template unchanging
During virtualization the cell will have its binding context updated, and so if an
app uses this mode it must ensure that binding context updates are handled
appropriately. All data about the cell must come from the binding context or
consistency errors may occur. This can be accomplished by using data binding to
display cell data. Alternatively, cell data should be set in the
OnBindingContextChanged override, rather than in the custom cell's
constructor.
• AVOID passing IEnumerable<T> as a data source to ListViews. Instead, try to
use IList<T>
• DO NOT nest ListView
10. • DO use HasUnevenRows where your ListView has rows of differing
sizes. If the content of the cell is modified dynamically (perhaps after
loading it from the database), be sure to call ForceUpdateSize() on the
cell
• ViewCell
• DO use AbsoluteLayout for ViewCell’s View
• DO load image inside ViewCell async and dow sample to viewsize with
FFImageLoading
• DO simpler UI, Reduce the size of the Visual Tree
• DON’T use Converter, it will block you UI
• DO await the PushAsync and PopAsync methods. Failure to do so is
detrimental to both performance and correctness
• AVOID hiding/showing the navigation bar.
• DO use the AppCompat backend for Android. This will improve both
performance and the look of the application
11.
12. • If your View usualy change and it’s height isn’t change (change only
width) you should put it into ContentView to reduce Layout Cycle call