SlideShare a Scribd company logo
1 of 16
Hà Nội – Xamarin Tech Talk
1. Xamarin Forms – Layout Performance
2. ListView scroll performance
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
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
}
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)
DO AND DON’T IN XAMARIN FORMS LAYOUT
• DO be aware of the Spacing (ColumnSpacing/RowSpacing for Grid)
and Padding properties
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
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.
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:
• 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
• 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
• 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
• DO Register Dependency Services manualy
Thanks for Listening

More Related Content

Similar to Hà nội – xamarin tech talk

iOS best practices
iOS best practicesiOS best practices
iOS best practicesMaxim Vialyx
 
Sql server ___________session_16(views)
Sql server  ___________session_16(views)Sql server  ___________session_16(views)
Sql server ___________session_16(views)Ehtisham Ali
 
Setting And Changing The Column Collation.Doc
Setting And Changing The Column Collation.DocSetting And Changing The Column Collation.Doc
Setting And Changing The Column Collation.Docwalsh010
 
Oracle - SQL-PL/SQL context switching
Oracle - SQL-PL/SQL context switchingOracle - SQL-PL/SQL context switching
Oracle - SQL-PL/SQL context switchingSmitha Padmanabhan
 
Django: Advanced Models
Django: Advanced ModelsDjango: Advanced Models
Django: Advanced ModelsYing-An Lai
 
DotNet programming & Practices
DotNet programming & PracticesDotNet programming & Practices
DotNet programming & PracticesDev Raj Gautam
 
Mohan Testing
Mohan TestingMohan Testing
Mohan Testingsmittal81
 
Best practices in Java
Best practices in JavaBest practices in Java
Best practices in JavaMudit Gupta
 
Coding Component (50)Weve provided you with an implementation .docx
Coding Component (50)Weve provided you with an implementation .docxCoding Component (50)Weve provided you with an implementation .docx
Coding Component (50)Weve provided you with an implementation .docxmary772
 
Sql coding-standard-sqlserver
Sql coding-standard-sqlserverSql coding-standard-sqlserver
Sql coding-standard-sqlserverlochaaaa
 
Object Oriented Programming with Laravel - Session 6
Object Oriented Programming with Laravel - Session 6Object Oriented Programming with Laravel - Session 6
Object Oriented Programming with Laravel - Session 6Shahrzad Peyman
 
Guide To Mastering The MySQL Query Execution Plan
Guide To Mastering The MySQL Query Execution PlanGuide To Mastering The MySQL Query Execution Plan
Guide To Mastering The MySQL Query Execution PlanOptimiz DBA
 
Adf performance tuning tips slideshare
Adf performance tuning tips slideshareAdf performance tuning tips slideshare
Adf performance tuning tips slideshareVinay Kumar
 
Share point 2013 coding standards and best practices 1.0
Share point 2013 coding standards and best practices 1.0Share point 2013 coding standards and best practices 1.0
Share point 2013 coding standards and best practices 1.0LiquidHub
 
How to Fine-Tune Performance Using Amazon Redshift
How to Fine-Tune Performance Using Amazon RedshiftHow to Fine-Tune Performance Using Amazon Redshift
How to Fine-Tune Performance Using Amazon RedshiftAWS Germany
 

Similar to Hà nội – xamarin tech talk (20)

iOS best practices
iOS best practicesiOS best practices
iOS best practices
 
Sql server ___________session_16(views)
Sql server  ___________session_16(views)Sql server  ___________session_16(views)
Sql server ___________session_16(views)
 
Setting And Changing The Column Collation.Doc
Setting And Changing The Column Collation.DocSetting And Changing The Column Collation.Doc
Setting And Changing The Column Collation.Doc
 
Oracle - SQL-PL/SQL context switching
Oracle - SQL-PL/SQL context switchingOracle - SQL-PL/SQL context switching
Oracle - SQL-PL/SQL context switching
 
Hello Android
Hello AndroidHello Android
Hello Android
 
Sql db optimization
Sql db optimizationSql db optimization
Sql db optimization
 
Django: Advanced Models
Django: Advanced ModelsDjango: Advanced Models
Django: Advanced Models
 
31 days Refactoring
31 days Refactoring31 days Refactoring
31 days Refactoring
 
DotNet programming & Practices
DotNet programming & PracticesDotNet programming & Practices
DotNet programming & Practices
 
Mohan Testing
Mohan TestingMohan Testing
Mohan Testing
 
Aem best practices
Aem best practicesAem best practices
Aem best practices
 
Best practices in Java
Best practices in JavaBest practices in Java
Best practices in Java
 
Coding Component (50)Weve provided you with an implementation .docx
Coding Component (50)Weve provided you with an implementation .docxCoding Component (50)Weve provided you with an implementation .docx
Coding Component (50)Weve provided you with an implementation .docx
 
Sql coding-standard-sqlserver
Sql coding-standard-sqlserverSql coding-standard-sqlserver
Sql coding-standard-sqlserver
 
Object Oriented Programming with Laravel - Session 6
Object Oriented Programming with Laravel - Session 6Object Oriented Programming with Laravel - Session 6
Object Oriented Programming with Laravel - Session 6
 
Guide To Mastering The MySQL Query Execution Plan
Guide To Mastering The MySQL Query Execution PlanGuide To Mastering The MySQL Query Execution Plan
Guide To Mastering The MySQL Query Execution Plan
 
Adf performance tuning tips slideshare
Adf performance tuning tips slideshareAdf performance tuning tips slideshare
Adf performance tuning tips slideshare
 
CoreData
CoreDataCoreData
CoreData
 
Share point 2013 coding standards and best practices 1.0
Share point 2013 coding standards and best practices 1.0Share point 2013 coding standards and best practices 1.0
Share point 2013 coding standards and best practices 1.0
 
How to Fine-Tune Performance Using Amazon Redshift
How to Fine-Tune Performance Using Amazon RedshiftHow to Fine-Tune Performance Using Amazon Redshift
How to Fine-Tune Performance Using Amazon Redshift
 

Recently uploaded

Work Remotely with Confluence ACE 2.pptx
Work Remotely with Confluence ACE 2.pptxWork Remotely with Confluence ACE 2.pptx
Work Remotely with Confluence ACE 2.pptxmavinoikein
 
Exploring protein-protein interactions by Weak Affinity Chromatography (WAC) ...
Exploring protein-protein interactions by Weak Affinity Chromatography (WAC) ...Exploring protein-protein interactions by Weak Affinity Chromatography (WAC) ...
Exploring protein-protein interactions by Weak Affinity Chromatography (WAC) ...Salam Al-Karadaghi
 
OSCamp Kubernetes 2024 | SRE Challenges in Monolith to Microservices Shift at...
OSCamp Kubernetes 2024 | SRE Challenges in Monolith to Microservices Shift at...OSCamp Kubernetes 2024 | SRE Challenges in Monolith to Microservices Shift at...
OSCamp Kubernetes 2024 | SRE Challenges in Monolith to Microservices Shift at...NETWAYS
 
CTAC 2024 Valencia - Sven Zoelle - Most Crucial Invest to Digitalisation_slid...
CTAC 2024 Valencia - Sven Zoelle - Most Crucial Invest to Digitalisation_slid...CTAC 2024 Valencia - Sven Zoelle - Most Crucial Invest to Digitalisation_slid...
CTAC 2024 Valencia - Sven Zoelle - Most Crucial Invest to Digitalisation_slid...henrik385807
 
OSCamp Kubernetes 2024 | A Tester's Guide to CI_CD as an Automated Quality Co...
OSCamp Kubernetes 2024 | A Tester's Guide to CI_CD as an Automated Quality Co...OSCamp Kubernetes 2024 | A Tester's Guide to CI_CD as an Automated Quality Co...
OSCamp Kubernetes 2024 | A Tester's Guide to CI_CD as an Automated Quality Co...NETWAYS
 
WhatsApp 📞 9892124323 ✅Call Girls In Juhu ( Mumbai )
WhatsApp 📞 9892124323 ✅Call Girls In Juhu ( Mumbai )WhatsApp 📞 9892124323 ✅Call Girls In Juhu ( Mumbai )
WhatsApp 📞 9892124323 ✅Call Girls In Juhu ( Mumbai )Pooja Nehwal
 
Simulation-based Testing of Unmanned Aerial Vehicles with Aerialist
Simulation-based Testing of Unmanned Aerial Vehicles with AerialistSimulation-based Testing of Unmanned Aerial Vehicles with Aerialist
Simulation-based Testing of Unmanned Aerial Vehicles with AerialistSebastiano Panichella
 
NATIONAL ANTHEMS OF AFRICA (National Anthems of Africa)
NATIONAL ANTHEMS OF AFRICA (National Anthems of Africa)NATIONAL ANTHEMS OF AFRICA (National Anthems of Africa)
NATIONAL ANTHEMS OF AFRICA (National Anthems of Africa)Basil Achie
 
Open Source Camp Kubernetes 2024 | Running WebAssembly on Kubernetes by Alex ...
Open Source Camp Kubernetes 2024 | Running WebAssembly on Kubernetes by Alex ...Open Source Camp Kubernetes 2024 | Running WebAssembly on Kubernetes by Alex ...
Open Source Camp Kubernetes 2024 | Running WebAssembly on Kubernetes by Alex ...NETWAYS
 
Philippine History cavite Mutiny Report.ppt
Philippine History cavite Mutiny Report.pptPhilippine History cavite Mutiny Report.ppt
Philippine History cavite Mutiny Report.pptssuser319dad
 
Microsoft Copilot AI for Everyone - created by AI
Microsoft Copilot AI for Everyone - created by AIMicrosoft Copilot AI for Everyone - created by AI
Microsoft Copilot AI for Everyone - created by AITatiana Gurgel
 
Genesis part 2 Isaiah Scudder 04-24-2024.pptx
Genesis part 2 Isaiah Scudder 04-24-2024.pptxGenesis part 2 Isaiah Scudder 04-24-2024.pptx
Genesis part 2 Isaiah Scudder 04-24-2024.pptxFamilyWorshipCenterD
 
OSCamp Kubernetes 2024 | Zero-Touch OS-Infrastruktur für Container und Kubern...
OSCamp Kubernetes 2024 | Zero-Touch OS-Infrastruktur für Container und Kubern...OSCamp Kubernetes 2024 | Zero-Touch OS-Infrastruktur für Container und Kubern...
OSCamp Kubernetes 2024 | Zero-Touch OS-Infrastruktur für Container und Kubern...NETWAYS
 
SBFT Tool Competition 2024 -- Python Test Case Generation Track
SBFT Tool Competition 2024 -- Python Test Case Generation TrackSBFT Tool Competition 2024 -- Python Test Case Generation Track
SBFT Tool Competition 2024 -- Python Test Case Generation TrackSebastiano Panichella
 
CTAC 2024 Valencia - Henrik Hanke - Reduce to the max - slideshare.pdf
CTAC 2024 Valencia - Henrik Hanke - Reduce to the max - slideshare.pdfCTAC 2024 Valencia - Henrik Hanke - Reduce to the max - slideshare.pdf
CTAC 2024 Valencia - Henrik Hanke - Reduce to the max - slideshare.pdfhenrik385807
 
Call Girls in Sarojini Nagar Market Delhi 💯 Call Us 🔝8264348440🔝
Call Girls in Sarojini Nagar Market Delhi 💯 Call Us 🔝8264348440🔝Call Girls in Sarojini Nagar Market Delhi 💯 Call Us 🔝8264348440🔝
Call Girls in Sarojini Nagar Market Delhi 💯 Call Us 🔝8264348440🔝soniya singh
 
The 3rd Intl. Workshop on NL-based Software Engineering
The 3rd Intl. Workshop on NL-based Software EngineeringThe 3rd Intl. Workshop on NL-based Software Engineering
The 3rd Intl. Workshop on NL-based Software EngineeringSebastiano Panichella
 
Call Girls in Rohini Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Rohini Delhi 💯Call Us 🔝8264348440🔝Call Girls in Rohini Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Rohini Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
call girls in delhi malviya nagar @9811711561@
call girls in delhi malviya nagar @9811711561@call girls in delhi malviya nagar @9811711561@
call girls in delhi malviya nagar @9811711561@vikas rana
 
Navi Mumbai Call Girls Service Pooja 9892124323 Real Russian Girls Looking Mo...
Navi Mumbai Call Girls Service Pooja 9892124323 Real Russian Girls Looking Mo...Navi Mumbai Call Girls Service Pooja 9892124323 Real Russian Girls Looking Mo...
Navi Mumbai Call Girls Service Pooja 9892124323 Real Russian Girls Looking Mo...Pooja Nehwal
 

Recently uploaded (20)

Work Remotely with Confluence ACE 2.pptx
Work Remotely with Confluence ACE 2.pptxWork Remotely with Confluence ACE 2.pptx
Work Remotely with Confluence ACE 2.pptx
 
Exploring protein-protein interactions by Weak Affinity Chromatography (WAC) ...
Exploring protein-protein interactions by Weak Affinity Chromatography (WAC) ...Exploring protein-protein interactions by Weak Affinity Chromatography (WAC) ...
Exploring protein-protein interactions by Weak Affinity Chromatography (WAC) ...
 
OSCamp Kubernetes 2024 | SRE Challenges in Monolith to Microservices Shift at...
OSCamp Kubernetes 2024 | SRE Challenges in Monolith to Microservices Shift at...OSCamp Kubernetes 2024 | SRE Challenges in Monolith to Microservices Shift at...
OSCamp Kubernetes 2024 | SRE Challenges in Monolith to Microservices Shift at...
 
CTAC 2024 Valencia - Sven Zoelle - Most Crucial Invest to Digitalisation_slid...
CTAC 2024 Valencia - Sven Zoelle - Most Crucial Invest to Digitalisation_slid...CTAC 2024 Valencia - Sven Zoelle - Most Crucial Invest to Digitalisation_slid...
CTAC 2024 Valencia - Sven Zoelle - Most Crucial Invest to Digitalisation_slid...
 
OSCamp Kubernetes 2024 | A Tester's Guide to CI_CD as an Automated Quality Co...
OSCamp Kubernetes 2024 | A Tester's Guide to CI_CD as an Automated Quality Co...OSCamp Kubernetes 2024 | A Tester's Guide to CI_CD as an Automated Quality Co...
OSCamp Kubernetes 2024 | A Tester's Guide to CI_CD as an Automated Quality Co...
 
WhatsApp 📞 9892124323 ✅Call Girls In Juhu ( Mumbai )
WhatsApp 📞 9892124323 ✅Call Girls In Juhu ( Mumbai )WhatsApp 📞 9892124323 ✅Call Girls In Juhu ( Mumbai )
WhatsApp 📞 9892124323 ✅Call Girls In Juhu ( Mumbai )
 
Simulation-based Testing of Unmanned Aerial Vehicles with Aerialist
Simulation-based Testing of Unmanned Aerial Vehicles with AerialistSimulation-based Testing of Unmanned Aerial Vehicles with Aerialist
Simulation-based Testing of Unmanned Aerial Vehicles with Aerialist
 
NATIONAL ANTHEMS OF AFRICA (National Anthems of Africa)
NATIONAL ANTHEMS OF AFRICA (National Anthems of Africa)NATIONAL ANTHEMS OF AFRICA (National Anthems of Africa)
NATIONAL ANTHEMS OF AFRICA (National Anthems of Africa)
 
Open Source Camp Kubernetes 2024 | Running WebAssembly on Kubernetes by Alex ...
Open Source Camp Kubernetes 2024 | Running WebAssembly on Kubernetes by Alex ...Open Source Camp Kubernetes 2024 | Running WebAssembly on Kubernetes by Alex ...
Open Source Camp Kubernetes 2024 | Running WebAssembly on Kubernetes by Alex ...
 
Philippine History cavite Mutiny Report.ppt
Philippine History cavite Mutiny Report.pptPhilippine History cavite Mutiny Report.ppt
Philippine History cavite Mutiny Report.ppt
 
Microsoft Copilot AI for Everyone - created by AI
Microsoft Copilot AI for Everyone - created by AIMicrosoft Copilot AI for Everyone - created by AI
Microsoft Copilot AI for Everyone - created by AI
 
Genesis part 2 Isaiah Scudder 04-24-2024.pptx
Genesis part 2 Isaiah Scudder 04-24-2024.pptxGenesis part 2 Isaiah Scudder 04-24-2024.pptx
Genesis part 2 Isaiah Scudder 04-24-2024.pptx
 
OSCamp Kubernetes 2024 | Zero-Touch OS-Infrastruktur für Container und Kubern...
OSCamp Kubernetes 2024 | Zero-Touch OS-Infrastruktur für Container und Kubern...OSCamp Kubernetes 2024 | Zero-Touch OS-Infrastruktur für Container und Kubern...
OSCamp Kubernetes 2024 | Zero-Touch OS-Infrastruktur für Container und Kubern...
 
SBFT Tool Competition 2024 -- Python Test Case Generation Track
SBFT Tool Competition 2024 -- Python Test Case Generation TrackSBFT Tool Competition 2024 -- Python Test Case Generation Track
SBFT Tool Competition 2024 -- Python Test Case Generation Track
 
CTAC 2024 Valencia - Henrik Hanke - Reduce to the max - slideshare.pdf
CTAC 2024 Valencia - Henrik Hanke - Reduce to the max - slideshare.pdfCTAC 2024 Valencia - Henrik Hanke - Reduce to the max - slideshare.pdf
CTAC 2024 Valencia - Henrik Hanke - Reduce to the max - slideshare.pdf
 
Call Girls in Sarojini Nagar Market Delhi 💯 Call Us 🔝8264348440🔝
Call Girls in Sarojini Nagar Market Delhi 💯 Call Us 🔝8264348440🔝Call Girls in Sarojini Nagar Market Delhi 💯 Call Us 🔝8264348440🔝
Call Girls in Sarojini Nagar Market Delhi 💯 Call Us 🔝8264348440🔝
 
The 3rd Intl. Workshop on NL-based Software Engineering
The 3rd Intl. Workshop on NL-based Software EngineeringThe 3rd Intl. Workshop on NL-based Software Engineering
The 3rd Intl. Workshop on NL-based Software Engineering
 
Call Girls in Rohini Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Rohini Delhi 💯Call Us 🔝8264348440🔝Call Girls in Rohini Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Rohini Delhi 💯Call Us 🔝8264348440🔝
 
call girls in delhi malviya nagar @9811711561@
call girls in delhi malviya nagar @9811711561@call girls in delhi malviya nagar @9811711561@
call girls in delhi malviya nagar @9811711561@
 
Navi Mumbai Call Girls Service Pooja 9892124323 Real Russian Girls Looking Mo...
Navi Mumbai Call Girls Service Pooja 9892124323 Real Russian Girls Looking Mo...Navi Mumbai Call Girls Service Pooja 9892124323 Real Russian Girls Looking Mo...
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
  • 13.
  • 14. • DO Register Dependency Services manualy
  • 15.