Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save atzimler/62e47b9832f6c0c002fac8e589c3e0f9 to your computer and use it in GitHub Desktop.
Save atzimler/62e47b9832f6c0c002fac8e589c3e0f9 to your computer and use it in GitHub Desktop.
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