Using XAML Resources
This page describes ho to deal with resources stored in XAML files
MauiReactor supports the XAML styling system. You can specify your resources in the startup stage with code as shown below:
var builder = MauiApp.CreateBuilder();
builder
.UseMauiReactorApp<ShellPage>(app =>
{
app.AddResource("Resources/Styles/DefaultTheme.xaml");
})
Every resource found in the specified files is directly accessible inside components just by accessing the Application.Resources dictionary:
new Button()
.Set(VisualElement.StyleProperty, Application.Current.Resources["MyStyle"])
It's even possible (but not recommended) to create a DynamicResource link between a DependencyProperty and a Resource using code like shown below:
new Button(buttonRef => buttonRef?.SetDynamicResource(VisualElement.StyleProperty, "MyStyle"))
DynamicResource in .NET MAUI allows you to "link" a dependency property to a Resource (like a Style for example) so that when you change the resource the dependency property is updated accordingly. MauiReactor doesn't play well with it because it directly refreshes dependency properties after component invalidation (for more info get a look at the Native vs Visual Tree page.
MauiReactor repo on GitHub contains the WeatherTwentyOne sample project that is a direct porting from a classic .NET MAUI project that makes heavy usage of XAML resource files (this is the link).
Last updated
Was this helpful?