Skip to content

Instantly share code, notes, and snippets.

@grokys
Created September 17, 2015 11:50
Show Gist options
  • Save grokys/4838edd8320d733e8896 to your computer and use it in GitHub Desktop.
Save grokys/4838edd8320d733e8896 to your computer and use it in GitHub Desktop.
public class DockPanel : Panel
{
protected override Size ArrangeOverride(Size finalSize)
{
foreach (var control in Children)
{
if (control.GetValue(DockProperty) == Dock.Left)
{
ArrangeToLeft(finalSize, control);
}
if (control.GetValue(DockProperty) == Dock.Right)
{
ArrangeToRight(finalSize, control);
}
}
return finalSize;
}
private static void ArrangeToRight(Size finalSize, IControl control)
{
var x = finalSize.Width - control.DesiredSize.Width;
var width = control.DesiredSize.Width;
control.Arrange(new Rect(x, 0, width, finalSize.Height));
}
private static void ArrangeToLeft(Size finalSize, IControl control)
{
control.Arrange(new Rect(0, 0, control.DesiredSize.Width, finalSize.Height));
}
public static readonly PerspexProperty<Dock> DockProperty = PerspexProperty.RegisterAttached<DockPanel, Control, Dock>("Dock");
public static Dock GetDock(PerspexObject element)
{
return element.GetValue(DockProperty);
}
public static void SetDock(PerspexObject element, Dock dock)
{
element.SetValue(DockProperty, dock);
}
public enum Dock
{
Bottom,
Left,
Right,
Top
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment