45 lines
1.3 KiB
C#
45 lines
1.3 KiB
C#
namespace Common.GUI.Controls
|
|
{
|
|
using System.Windows;
|
|
using System.Windows.Controls;
|
|
using System.Windows.Markup;
|
|
|
|
[ContentProperty(nameof(Content))]
|
|
public partial class MainLayout : Grid
|
|
{
|
|
public static readonly DependencyProperty ContentProperty = DependencyProperty.Register(
|
|
name: nameof(Content)
|
|
, propertyType: typeof(Grid)
|
|
, ownerType: typeof(MainLayout)
|
|
, typeMetadata: new PropertyMetadata(default(Grid), ContentChanged));
|
|
|
|
public MainLayout() => this.InitializeComponent();
|
|
|
|
public Grid Content
|
|
{
|
|
get => this.GetValue(ContentProperty) as Grid;
|
|
set => this.SetValue(ContentProperty, value);
|
|
}
|
|
|
|
private static void ContentChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs args)
|
|
{
|
|
if (dependencyObject is MainLayout mainLayout)
|
|
{
|
|
var children = mainLayout.Children;
|
|
|
|
if (args.OldValue is UIElement oldContent)
|
|
{
|
|
children.Remove(oldContent);
|
|
}
|
|
|
|
if (args.NewValue is UIElement newContent)
|
|
{
|
|
children.Insert(1, newContent);
|
|
|
|
Grid.SetRow(newContent, 1);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|