csharpc-sharpdotnetxamlavaloniauicross-platformcross-platform-xamlavaloniaguimulti-platformuser-interfacedotnetcore
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
103 lines
3.7 KiB
103 lines
3.7 KiB
// 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
|
|
{
|
|
/// <summary>
|
|
/// Displays <see cref="Content"/> according to a <see cref="FuncDataTemplate"/>.
|
|
/// </summary>
|
|
public class ContentControl : TemplatedControl, IContentControl, IContentPresenterHost
|
|
{
|
|
/// <summary>
|
|
/// Defines the <see cref="Content"/> property.
|
|
/// </summary>
|
|
public static readonly StyledProperty<object> ContentProperty =
|
|
AvaloniaProperty.Register<ContentControl, object>(nameof(Content));
|
|
|
|
/// <summary>
|
|
/// Defines the <see cref="ContentTemplate"/> property.
|
|
/// </summary>
|
|
public static readonly StyledProperty<IDataTemplate> ContentTemplateProperty =
|
|
AvaloniaProperty.Register<ContentControl, IDataTemplate>(nameof(ContentTemplate));
|
|
|
|
/// <summary>
|
|
/// Defines the <see cref="HorizontalContentAlignment"/> property.
|
|
/// </summary>
|
|
public static readonly StyledProperty<HorizontalAlignment> HorizontalContentAlignmentProperty =
|
|
AvaloniaProperty.Register<ContentControl, HorizontalAlignment>(nameof(HorizontalContentAlignment));
|
|
|
|
/// <summary>
|
|
/// Defines the <see cref="VerticalContentAlignment"/> property.
|
|
/// </summary>
|
|
public static readonly StyledProperty<VerticalAlignment> VerticalContentAlignmentProperty =
|
|
AvaloniaProperty.Register<ContentControl, VerticalAlignment>(nameof(VerticalContentAlignment));
|
|
|
|
/// <summary>
|
|
/// Initializes static members of the <see cref="ContentControl"/> class.
|
|
/// </summary>
|
|
static ContentControl()
|
|
{
|
|
ContentControlMixin.Attach<ContentControl>(ContentProperty, x => x.LogicalChildren);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets or sets the content to display.
|
|
/// </summary>
|
|
[Content]
|
|
[DependsOn(nameof(ContentTemplate))]
|
|
public object Content
|
|
{
|
|
get { return GetValue(ContentProperty); }
|
|
set { SetValue(ContentProperty, value); }
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets or sets the data template used to display the content of the control.
|
|
/// </summary>
|
|
public IDataTemplate ContentTemplate
|
|
{
|
|
get { return GetValue(ContentTemplateProperty); }
|
|
set { SetValue(ContentTemplateProperty, value); }
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets the presenter from the control's template.
|
|
/// </summary>
|
|
public IContentPresenter Presenter
|
|
{
|
|
get;
|
|
private set;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets or sets the horizontal alignment of the content within the control.
|
|
/// </summary>
|
|
public HorizontalAlignment HorizontalContentAlignment
|
|
{
|
|
get { return GetValue(HorizontalContentAlignmentProperty); }
|
|
set { SetValue(HorizontalContentAlignmentProperty, value); }
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets or sets the vertical alignment of the content within the control.
|
|
/// </summary>
|
|
public VerticalAlignment VerticalContentAlignment
|
|
{
|
|
get { return GetValue(VerticalContentAlignmentProperty); }
|
|
set { SetValue(VerticalContentAlignmentProperty, value); }
|
|
}
|
|
|
|
/// <inheritdoc/>
|
|
void IContentPresenterHost.RegisterContentPresenter(IContentPresenter presenter)
|
|
{
|
|
Presenter = presenter;
|
|
}
|
|
}
|
|
}
|
|
|