Table of Contents

Class ViewModelLocator

Namespace
Crystal.Avalonia
Assembly
Crystal.Avalonia.dll

Provides automatic ViewModel binding via an attached property. Independent of EnableViewLocator on the app options instance, which only gates ViewModel-first view location.

public class ViewModelLocator
Inheritance
ViewModelLocator
Inherited Members

Remarks

When AutoWireViewModel is set to True, the system automatically resolves the corresponding ViewModel from the DI container and assigns it to the control's DataContext.

Fields

AutoWireViewModelProperty

Identifies the AutoWireViewModelProperty attached property registration. When set to True, the system automatically binds the corresponding ViewModel to the control's DataContext.

public static readonly AttachedProperty<bool> AutoWireViewModelProperty

Field Value

AttachedProperty<bool>

Methods

GetAutoWireViewModel(Control)

Gets the AutoWireViewModel attached property value for the specified control.

public static bool GetAutoWireViewModel(Control element)

Parameters

element Control

The control to query.

Returns

bool

True if the control has automatic ViewModel binding enabled.

SetAutoWireViewModel(Control, bool?)

Sets the AutoWireViewModel attached property value for the specified control.

public static void SetAutoWireViewModel(Control element, bool? value)

Parameters

element Control

The control to set.

value bool?

Whether to enable automatic binding.