// Copyright (c) The Avalonia Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
using Avalonia.Controls.Mixins;
using Avalonia.Controls.Presenters;
using Avalonia.Controls.Primitives;
using Avalonia.Controls.Templates;
using Avalonia.Layout;
using Avalonia.Metadata;
namespace Avalonia.Controls
{
///
/// Displays according to a .
///
public class ContentControl : TemplatedControl, IContentControl, IContentPresenterHost
{
///
/// Defines the property.
///
public static readonly StyledProperty ContentProperty =
AvaloniaProperty.Register(nameof(Content));
///
/// Defines the property.
///
public static readonly StyledProperty ContentTemplateProperty =
AvaloniaProperty.Register(nameof(ContentTemplate));
///
/// Defines the property.
///
public static readonly StyledProperty HorizontalContentAlignmentProperty =
AvaloniaProperty.Register(nameof(HorizontalContentAlignment));
///
/// Defines the property.
///
public static readonly StyledProperty VerticalContentAlignmentProperty =
AvaloniaProperty.Register(nameof(VerticalContentAlignment));
///
/// Initializes static members of the class.
///
static ContentControl()
{
ContentControlMixin.Attach(ContentProperty, x => x.LogicalChildren);
}
///
/// Gets or sets the content to display.
///
[Content]
[DependsOn(nameof(ContentTemplate))]
public object Content
{
get { return GetValue(ContentProperty); }
set { SetValue(ContentProperty, value); }
}
///
/// Gets or sets the data template used to display the content of the control.
///
public IDataTemplate ContentTemplate
{
get { return GetValue(ContentTemplateProperty); }
set { SetValue(ContentTemplateProperty, value); }
}
///
/// Gets the presenter from the control's template.
///
public IContentPresenter Presenter
{
get;
private set;
}
///
/// Gets or sets the horizontal alignment of the content within the control.
///
public HorizontalAlignment HorizontalContentAlignment
{
get { return GetValue(HorizontalContentAlignmentProperty); }
set { SetValue(HorizontalContentAlignmentProperty, value); }
}
///
/// Gets or sets the vertical alignment of the content within the control.
///
public VerticalAlignment VerticalContentAlignment
{
get { return GetValue(VerticalContentAlignmentProperty); }
set { SetValue(VerticalContentAlignmentProperty, value); }
}
///
void IContentPresenterHost.RegisterContentPresenter(IContentPresenter presenter)
{
Presenter = presenter;
}
}
}