Changes

XAML Best practices

2,051 bytes added, 15 July
/* Performance */
** 🏆 '''Alternatives to the optimized ListViews should be used with extreme caution.''' Controls such as CollectionView or BindableLayout are not optimized for good performance in UBIK.
[[Category:Pages with broken file links|XAML Best practices]][[Category:XAML|XAML Best practices]]
=== Using Styles and Templates ===
=== Performance analysis (MAUI only) ===
In the MAUI app, {{UBIK}} provides customizers a possibility to analyze the performance of specific UI elements by measuring the time it takes to render them. This can help customizers find performance weak spots in the entire UI and also serve as a benchmarking tool to verify the result of any improvement attempts.
The measurement is achieved through the use of the MeasurePerformanceBehavior. The concept of it is very similar to other behaviors, namely you attach it to any UI element in the XAML code (as long as it's a derivate of the [https://learn.microsoft.com/en-us/dotnet/api/microsoft.maui.controls.visualelement?view=net-maui-9.0 VisualElement], which should cover the vast majority of all UI element types).
* The behavior measures the time to render the UI element (which it attaches to) as well as its child elements (recursively if any).
* You can attach multiple behaviors to multiple UI elements at the same time, one to each, in order to get the measurements of the different elements.
* The measurements are logged in the UBIKDebug.log file under the app's Logs folder.
* You can and should assign a unique name to the Label property of the behavior, so that it's easy to identify the render time of the target element.
The following is an example of attaching the behavior to the root Grid inside the UBIKChildItem template. It should effectively measure the time to render the UI for a child item.
 
<tabs>
<tab name="MAUI">
<source lang = "xml">
<Grid xmlns:behaviors="clr-namespace:UBIK.MAUI.Behaviors;assembly=UBIK.MAUI">
<Grid.Behaviors>
<behaviors:MeasurePerformanceBehavior Label="UBIKChildItemRootGrid" />
</Grid.Behaviors>
...
</Grid>
</source>
</tab>
</tabs>
 
With this, you should see log entries such as the following, one for every child item that you see when opening a content page.
 
<pre>2025.07.15 12:12:18:1030 Debug Sender: MeasurePerformanceBehavior Message:'Rendering Microsoft.Maui.Controls.Grid UBIKChildItemRootGrid took 8.4889 ms'</pre>
 
[[Category:Pages with broken file links|XAML Best practices]]
[[Category:XAML|XAML Best practices]]
== Templating ==