private void SetColumns() { var starAuto = new GridLength[] { new GridLength(1, GridUnitType.Star), GridLength.Auto }; var autoStar = starAuto.Reverse(); switch (Direction) { case FlowDirection.RightToLeft: SetColumnDefinitions((GetTemplateChild("root") as Grid).ColumnDefinitions, starAuto); SetColumnDefinitions((GetTemplateChild("side") as Grid).ColumnDefinitions, autoStar); Grid.SetColumn((GetTemplateChild("rect") as FrameworkElement), 1); Grid.SetColumn((GetTemplateChild("viewbox") as FrameworkElement), 0); Grid.SetColumn((GetTemplateChild("side") as FrameworkElement), 1); Grid.SetColumn((GetTemplateChild("RootGrid") as FrameworkElement), 0); break; case FlowDirection.LeftToRight: SetColumnDefinitions((GetTemplateChild("root") as Grid).ColumnDefinitions, autoStar); SetColumnDefinitions((GetTemplateChild("side") as Grid).ColumnDefinitions, starAuto); Grid.SetColumn((GetTemplateChild("rect") as FrameworkElement), 0); Grid.SetColumn((GetTemplateChild("viewbox") as FrameworkElement), 1); Grid.SetColumn((GetTemplateChild("side") as FrameworkElement), 0); Grid.SetColumn((GetTemplateChild("RootGrid") as FrameworkElement), 1); break; } }