🏗️
MauiReactor
  • What is MauiReactor?
  • What's new in Version 2
  • What's new in Version 3
  • Getting Started
  • Getting Started Version 2
  • Components
    • State-less Components
    • Stateful Components
      • Inline Components
    • Component life-cycle
    • Component Properties
    • Component with children
    • Component Parameters
    • Theming
    • Navigation
      • NavigationPage
      • Shell
      • Back button
    • Controls
      • Button
      • RadioButton
      • FlyoutPage
      • CollectionView
        • Interactions
        • Layout
        • Selection
        • Empty view
        • Scrolling
        • Grouping
      • IndicatorView
      • Picker
      • Shell
      • Label
    • Wrap 3rd party controls
      • Lottie animations
      • Provide DataTemplate to native controls
    • Accessing native controls
    • Animation
      • Property-Based
      • AnimationController
      • Timer
    • Graphics
      • CanvasView control
    • Window
    • Testing
    • XAML Integration
  • Deep dives
    • Native tree and Visual tree
    • Dependency injection
    • Working with the GraphicsView
    • Migrating from MVVM Model
    • Using XAML Resources
    • Behaviors
  • resources
    • Source and Sample Applications
  • Q&A
    • How to deal with state shared across Components?
    • Does this support ObservableCollection for CollectionView?
    • Do we need to add states to create simple animations such as ScaleTo, FadeTo, etc on tap?
    • How to deal with custom dialogs/popups?
  • How to create a Menu/ContextMenu?
Powered by GitBook
On this page

Was this helpful?

Edit on GitHub
  1. Deep dives

Using XAML Resources

This page describes ho to deal with resources stored in XAML files

PreviousMigrating from MVVM ModelNextBehaviors

Last updated 2 years ago

Was this helpful?

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");
    })

Hot-reloading an application that links XAML files may require you to set the Full mode option: dotnet-maui-reactor -f net6.0-android --mode Full

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"])

Even if technically doable it's not possible to store or retrieve resources from the VisualElement.Resources dictionary. Resource lookup (from the current VisualElement up to the Application) is actually discouraged in MauiReactor while it's perfectly fine to have all the resources in files that are linked at startup as shown above.

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 .

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 ).

Native vs Visual Tree page
link