🏗️
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
  • Set native controls dependency properties
  • Get reference to native controls

Was this helpful?

Edit on GitHub
  1. Components

Accessing native controls

Describes how access the underling native control

Set native controls dependency properties

Sometimes, you need to set a specific dependency property of the native control:

new Button()
    .Set(BindableProperty property, object? value);

If you want to set an attached dependency property:

new Button()
    .SetAttachedProperty(BindableProperty property, object? value);

Get reference to native controls

Sometimes you need a reference to the native control (i.e. MAUI control); for example, say you need to move focus to Entry control when the component starts up.

In MauiReactor, you can get a reference to the underlying widget passing an Action argument when constructing the visual object accepting the reference to the native control: you can easily save it in a private field and reuse it wherever.

For example, in this code when a button is clicked, the textbox (i.e. Entry) is focused:

public class MainPage : Component
{
    private MauiControls.Entry _entryRef;

    public override VisualNode Render()
    {
        return new ContentPage()
        {
            new VStack(spacing: 10)
            {
                new Entry(entryRef => _entryRef = entryRef),
            
                new Button("Click here!")
                    .OnClick(OnButtonClicked)
                    .VCenter()
                    .HCenter()
            }
        };
    }

    private void OnButtonClicked()
        => _entryRef?.Focus();
}

The page containing the current component is also accessible with the convenient ContainerPage property

PreviousProvide DataTemplate to native controlsNextAnimation

Last updated 1 month ago

Was this helpful?