EllipseButton CreateBaseButton <T>(T icon, double scale) { var button = new EllipseButton() { Width = BUTTON_SIZE, Height = BUTTON_SIZE, HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Bottom, Margin = new Thickness(0), RenderTransform = new CompositeTransform() { TranslateX = 0, TranslateY = 0, ScaleX = scale, ScaleY = scale, CenterX = BUTTON_SIZE / 2, CenterY = BUTTON_SIZE, }, }; button.Clicked += ElementTapped; if (typeof(T) == typeof(BitmapImage)) { button.Icon = icon as BitmapImage; } else if (typeof(T) == typeof(DataTemplate)) { button.IconTemplate = icon as DataTemplate; } return(button); }
/// <summary> /// Clear all buttons and create new buttons. /// </summary> /// <param name="info"></param> void UpdateCandidates(ShootModeInfo info) { if (info == null) { return; } var targetShootMode = info.ShootModeCapability.Current; var selectedIndex = FindCandidateIndex(info.ShootModeCapability, targetShootMode); int currentIndex = 0; Buttons.Children.Clear(); foreach (var i in info.ShootModeCapability.Candidates) { var scale = i == targetShootMode ? 1.0 : 0.6; double newX = (currentIndex - selectedIndex) * 50; if (newX < 0) { newX -= 30; } else if (newX > 0) { newX += 30; } EllipseButton button = null; if (selectedIndex == currentIndex) { if (CurrentModeButtonTemplate != null) { button = CreateBaseButton(CurrentModeButtonTemplate, scale); } else { button = CreateBaseButton(CurrentModeButtonImage, scale); } } else { if (info.IconTemplates?.ContainsKey(i) ?? false) { button = CreateBaseButton(info.IconTemplates[i], scale); } else if (info.Icons?.ContainsKey(i) ?? false) { button = CreateBaseButton(info.Icons[i], scale); } } if (button != null) { Buttons.Children.Add(button); (button.RenderTransform as CompositeTransform).TranslateX = newX; } currentIndex++; } }