private void GenerateButtons(Panel canvas, ICollection <int> range, double radiusRatio, IValueConverter isCheckedConverter, Func <int, string> stylePropertySelector, string format, ClockDisplayMode clockDisplayMode) { var anglePerItem = 360.0 / range.Count; var radiansPerItem = anglePerItem * (Math.PI / 180); //nothing fancy with sizing/measuring...we are demanding a height if (canvas.Width < 10.0 || Math.Abs(canvas.Height - canvas.Width) > 0.0) { return; } _centreCanvas = new Point(canvas.Width / 2, canvas.Height / 2); var hypotenuseRadius = _centreCanvas.X * radiusRatio; foreach (var i in range) { var button = new ClockItemButton(); button.SetBinding(StyleProperty, GetBinding(stylePropertySelector(i))); var adjacent = Math.Cos(i * radiansPerItem) * hypotenuseRadius; var opposite = Math.Sin(i * radiansPerItem) * hypotenuseRadius; button.CentreX = _centreCanvas.X + opposite; button.CentreY = _centreCanvas.Y - adjacent; button.SetBinding(ToggleButton.IsCheckedProperty, GetBinding("Time", converter: isCheckedConverter, converterParameter: i)); button.SetBinding(Canvas.LeftProperty, GetBinding("X", button)); button.SetBinding(Canvas.TopProperty, GetBinding("Y", button)); button.Content = (i == 60 ? 0 : (i == 24 && clockDisplayMode == ClockDisplayMode.Hours ? 0 : i)).ToString(format); canvas.Children.Add(button); } }
private void GenerateButtons(Panel canvas, ICollection <int> range, double radiusRatio, IValueConverter isCheckedConverter, Func <int, string> stylePropertySelector, string format, int interval = 1) { var anglePerItem = 360.0 / range.Count; var radiansPerItem = anglePerItem * (Math.PI / 180); //nothing fancy with sizing/measuring...we are demanding a height if (canvas.Width < 10.0 || Math.Abs(canvas.Height - canvas.Width) > 0.0) { return; } _centreCanvas = new Point(canvas.Width / 2, canvas.Height / 2); var hypotenuseRadius = _centreCanvas.X * radiusRatio; var lastItem = range.LastOrDefault(); range = range.Where(i => i % interval == 0).ToList(); //generate buttons only for values % the given interval if (!range.Contains(lastItem)) { range.Add(lastItem); //zero value should always be displayed (item 24 or 60) } foreach (var i in range) { var button = new ClockItemButton(); button.SetBinding(StyleProperty, GetBinding(stylePropertySelector(i))); var adjacent = Math.Cos(i * radiansPerItem) * hypotenuseRadius; var opposite = Math.Sin(i * radiansPerItem) * hypotenuseRadius; button.CentreX = _centreCanvas.X + opposite; button.CentreY = _centreCanvas.Y - adjacent; button.SetBinding(ToggleButton.IsCheckedProperty, GetBinding("Time", converter: isCheckedConverter, converterParameter: i)); button.SetBinding(Canvas.LeftProperty, GetBinding("X", button)); button.SetBinding(Canvas.TopProperty, GetBinding("Y", button)); button.Content = (i == 60 ? 0 : (i == 24 ? 0 : i)).ToString(format); canvas.Children.Add(button); } }
private void GenerateButtons(Panel canvas, ICollection<int> range, double radiusRatio, IValueConverter isCheckedConverter, Func<int, string> stylePropertySelector, string format) { var anglePerItem = 360.0 / range.Count; var radiansPerItem = anglePerItem * (Math.PI / 180); //nothing fancy with sizing/measuring...we are demanding a height if (canvas.Width < 10.0 || Math.Abs(canvas.Height - canvas.Width) > 0.0) return; _centreCanvas = new Point(canvas.Width / 2, canvas.Height / 2); var hypotenuseRadius = _centreCanvas.X * radiusRatio; foreach (var i in range) { var button = new ClockItemButton(); button.SetBinding(StyleProperty, GetBinding(stylePropertySelector(i))); var adjacent = Math.Cos(i*radiansPerItem)*hypotenuseRadius; var opposite = Math.Sin(i*radiansPerItem)*hypotenuseRadius; button.CentreX = _centreCanvas.X + opposite; button.CentreY = _centreCanvas.Y - adjacent; button.SetBinding(ToggleButton.IsCheckedProperty, GetBinding("Time", converter: isCheckedConverter, converterParameter: i)); button.SetBinding(Canvas.LeftProperty, GetBinding("X", button)); button.SetBinding(Canvas.TopProperty, GetBinding("Y", button)); button.Content = (i == 60 ? 0 : (i == 24 ? 0 : i)).ToString(format); canvas.Children.Add(button); } }