Skip to content

TemplatedTaskLoader Events Now Include Actual View

Latest

Choose a tag to compare

@roubachof roubachof released this 24 Oct 02:31

Release Notes

Version 2.6.3 (2025-10-24)

Enhanced Features

TemplatedTaskLoader Events Now Include Actual View

The TemplatedTaskLoader events have been significantly enhanced! All four events now pass the actual view created from the ControlTemplate via the new ControlTemplateLoadedEventArgs class:

  • ResultControlTemplateLoaded - Now includes the result view in e.View
  • LoadingControlTemplateLoaded - Now includes the loading view in e.View
  • ErrorControlTemplateLoaded - Now includes the error view in e.View
  • EmptyControlTemplateLoaded - Now includes the empty view in e.View

New GetTemplateChild Method

Added GetTemplateChild(string name) method to easily retrieve named children from within the control template.

Usage Examples

Accessing the view from events:

myTemplatedTaskLoader.LoadingControlTemplateLoaded += (sender, e) => 
{
    if (e.View is ActivityIndicator indicator)
    {
        // Directly manipulate the loading indicator
        indicator.Color = Colors.Red;
        Console.WriteLine($"Loading indicator is running: {indicator.IsRunning}");
    }
};

myTemplatedTaskLoader.ResultControlTemplateLoaded += (sender, e) => 
{
    if (e.View is Grid grid)
    {
        // Access and modify the result view
        Console.WriteLine($"Result grid has {grid.Children.Count} children");
        // Add custom behavior, animations, etc.
    }
};

Using GetTemplateChild to find named elements:

<tlv:TemplatedTaskLoader.LoadingControlTemplate>
    <ControlTemplate>
        <ActivityIndicator x:Name="MyLoadingIndicator" 
                          Color="{StaticResource AccentColor}" />
    </ControlTemplate>
</tlv:TemplatedTaskLoader.LoadingControlTemplate>
// Find and manipulate named children
var indicator = myTemplatedTaskLoader.GetTemplateChild("MyLoadingIndicator") as ActivityIndicator;
if (indicator != null)
{
    indicator.Scale = 1.5;
}

Technical Implementation

This enhancement uses reflection to access MAUI's internal TemplateRoot property, which contains the actual view created from the ControlTemplate. The implementation is robust and includes proper error handling for future MAUI version compatibility.

Benefits

  • Full view access: Directly manipulate views created from templates
  • Custom animations: Add or trigger animations when states change
  • Dynamic styling: Change appearance based on runtime conditions
  • Advanced debugging: Inspect and validate template structure
  • Named element access: Easily find specific controls within templates