Created
May 24, 2017 12:13
-
-
Save atzimler/62e47b9832f6c0c002fac8e589c3e0f9 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
private static void UpdateSide(DependencyObject d, DependencyPropertyChangedEventArgs e) | |
{ | |
var obj = (FrameworkElement)d; | |
// Finding the LeftRightLayoutControl to which this object belongs to either directly or indirectly. | |
var parent = LogicalTreeHelper.GetParent(obj); | |
while (parent != null && parent.GetType() != typeof(LeftRightLayoutControl)) | |
{ | |
parent = LogicalTreeHelper.GetParent(parent); | |
} | |
var layoutControl = (LeftRightLayoutControl)parent; | |
// Detaching the object from the current logical parent. | |
((StackPanel)obj.Parent).Children.Remove(obj); | |
// Reattaching the object to the correct logical parent based on the new value. | |
var value = (Side)e.NewValue; | |
if (value == Side.Left) | |
{ | |
layoutControl._left.Children.Add(obj); | |
} | |
else if (value == Side.Right) | |
{ | |
layoutControl._right.Children.Add(obj); | |
} | |
else | |
{ | |
layoutControl.Children.Add(obj); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment