Created
September 17, 2015 11:50
-
-
Save grokys/4838edd8320d733e8896 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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