Beispiel #1
0
        /// <summary>
        /// Creates the clock hand.
        /// </summary>
        /// <param name="hand">Reference to the clock hand being created.</param>
        /// <param name="name">The name of the clock hand.</param>
        /// <param name="color">The color of the clock hand.</param>
        /// <param name="widthDiv">The width divider.</param>
        /// <param name="heightDiv">The height divider.</param>
        /// <param name="minWidth">Minimum width of the clock hand to have a border.</param>
        private void CreateHand(ref Rectangle hand, string name, Brush color, int widthDiv, double heightDiv, int minWidth)
        {
            double size = this.ActualWidth;
            string handName = name + "Hand";
            string angleName = Char.ToUpper(name[0]).ToString() + name.Substring(1) + "Angle";

            hand = new Rectangle();
            NameScope.SetNameScope(hand, new NameScope());
            hand.Name = handName;
            hand.RegisterName(handName, hand);
            hand.Width = size / widthDiv;
            hand.Height = size / heightDiv;
            hand.Fill = color;
            hand.Stroke = null;
            if (hand.Width >= minWidth)
            {
                hand.Stroke = new SolidColorBrush(Color.FromArgb(0xB0, 0xB0, 0xB0, 0xB0));
            }

            hand.RadiusX = hand.RadiusY = 2;
            hand.RenderTransformOrigin = new Point(0.0, 0.0);
            TransformGroup transformGroup = new TransformGroup();
            transformGroup.Children.Add(new TranslateTransform(-(hand.Width / 2), (hand.Width / 2) - hand.Height));
            transformGroup.Children.Add(new RotateTransform());
            transformGroup.Children.Add(new TranslateTransform((size / 2), (size / 2)));
            hand.SetBinding(RotateTransform.AngleProperty, new Binding(angleName));
            hand.RenderTransform = transformGroup;
        }