using System;
namespace Avalonia.Data
{
///
/// Defines the mode of a object.
///
public enum RelativeSourceMode
{
///
/// The binding will be to the control's data context.
///
DataContext,
///
/// The binding will be to the control's templated parent.
///
TemplatedParent,
///
/// The binding will be to the control itself.
///
Self,
///
/// The binding will be to an ancestor of the control in the visual tree.
///
FindAncestor,
}
///
/// The type of tree via which to track a control.
///
public enum TreeType
{
///
/// The visual tree.
///
Visual,
///
/// The logical tree.
///
Logical,
}
///
/// Describes the location of a binding source, relative to the binding target.
///
public class RelativeSource
{
private int _ancestorLevel = 1;
///
/// Initializes a new instance of the class.
///
///
/// This constructor initializes to .
///
public RelativeSource()
{
Mode = RelativeSourceMode.FindAncestor;
}
///
/// Initializes a new instance of the class.
///
/// The relative source mode.
public RelativeSource(RelativeSourceMode mode)
{
Mode = mode;
}
///
/// Gets the level of ancestor to look for when in mode.
///
///
/// Use the default value of 1 to look for the first ancestor of the specified type.
///
public int AncestorLevel
{
get { return _ancestorLevel; }
set
{
if (value <= 0)
{
throw new ArgumentOutOfRangeException(nameof(value), "AncestorLevel may not be set to less than 1.");
}
_ancestorLevel = value;
}
}
///
/// Gets the type of ancestor to look for when in mode.
///
public Type? AncestorType { get; set; }
///
/// Gets or sets a value that describes the type of relative source lookup.
///
public RelativeSourceMode Mode { get; set; }
public TreeType Tree { get; set; } = TreeType.Visual;
}
}