45 lines
1.4 KiB
C#
45 lines
1.4 KiB
C#
namespace Common.GUI.Controls
|
|
{
|
|
using System.Windows;
|
|
using System.Windows.Controls;
|
|
using System.Windows.Markup;
|
|
|
|
[ContentProperty(nameof(Body))]
|
|
public partial class MainLayout : Grid
|
|
{
|
|
private static readonly DependencyProperty BodyProperty = DependencyProperty.Register(
|
|
name: nameof(Body)
|
|
, propertyType: typeof(Panel)
|
|
, ownerType: typeof(MainLayout)
|
|
, typeMetadata: new FrameworkPropertyMetadata(
|
|
defaultValue: default(Panel)
|
|
, propertyChangedCallback: BodyChanged));
|
|
|
|
public MainLayout() => this.InitializeComponent();
|
|
|
|
public Panel Body
|
|
{
|
|
get => this.GetValue(BodyProperty) as Panel;
|
|
set => this.SetValue(BodyProperty, value);
|
|
}
|
|
|
|
private static void BodyChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs args)
|
|
{
|
|
if (dependencyObject is MainLayout mainLayout)
|
|
{
|
|
if (args.OldValue is UIElement oldElement)
|
|
{
|
|
mainLayout.Children.Remove(oldElement);
|
|
}
|
|
|
|
if (args.NewValue is UIElement newElement)
|
|
{
|
|
mainLayout.Children.Add(newElement);
|
|
|
|
Grid.SetRow(newElement, 1);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|