Esempio n. 1
0
        /// <summary>
        /// Resize the analogue clock based on the smallest of its width and height
        /// </summary>
        private void AnalogueClockSize()
        {
            try
            {
                ParentGrid.Height   = MyGrid.RowDefinitions.FirstOrDefault().ActualHeight;
                ParentGrid.Width    = MyGrid.ColumnDefinitions.FirstOrDefault().ActualWidth;
                TBlockTime.FontSize = MyGrid.RowDefinitions.FirstOrDefault().ActualHeight * 0.30;

                ParentGrid.UpdateLayout();
                TBlockTime.UpdateLayout();

                //Parent meassurements
                int clockParentWidth  = (int)ParentGrid.ActualWidth;
                int clockParentHeight = (int)ParentGrid.RowDefinitions.FirstOrDefault().ActualHeight;

                clockHandler.SizeCalc(clockParentWidth, clockParentHeight);

                int clockDiameter = clockHandler.Diameter;
                int radius        = clockHandler.Radius;

                //Clock meassurements
                AnalogueClockEllipsis.Height = clockDiameter;
                AnalogueClockEllipsis.Width  = clockDiameter;

                //Arm Width (Length)
                rectangleSecond.Width = clockHandler.ArmSLength;
                rectangleMinute.Width = clockHandler.ArmMLength;
                rectangleHour.Width   = clockHandler.ArmHLength;

                //Arm Height
                rectangleSecond.Height = clockHandler.ArmSHeight;
                rectangleMinute.Height = clockHandler.ArmMHeight;
                rectangleHour.Height   = clockHandler.ArmHHeight;

                //Margin for arm offset
                rectangleSecond.Margin = new Thickness(rectangleSecond.Width, 0, 0, 0);;
                rectangleMinute.Margin = new Thickness(rectangleMinute.Width, 0, 0, 0);;
                rectangleHour.Margin   = new Thickness(rectangleHour.Width, 0, 0, 0);;

                //Offset for animation center
                secondHand.CenterY = rectangleSecond.Height / 2;
                minuteHand.CenterY = rectangleMinute.Height / 2;
                hourHand.CenterY   = rectangleHour.Height / 2;

                //Timestamps -TextBlocks- coord and size
                double dist   = clockHandler.TxtDist;
                double coordY = clockHandler.TxtCoordX;
                double coordX = clockHandler.TxtCoordY;

                //Can this be List<>() looped?
                TBlockTwelve.Margin = new Thickness(0, -dist, 0, 0);
                TBlockOne.Margin    = new Thickness(coordY, -coordX, 0, 0);
                TBlockTwo.Margin    = new Thickness(coordX, -coordY, 0, 0);
                TBlockThree.Margin  = new Thickness(dist, 0, 0, 0);
                TBlockFour.Margin   = new Thickness(coordX, coordY, 0, 0);
                TBlockFive.Margin   = new Thickness(coordY, coordX, 0, 0);
                TBlockSix.Margin    = new Thickness(0, dist, 0, 0);
                TBlockSeven.Margin  = new Thickness(-coordY, coordX, 0, 0);
                TBlockEight.Margin  = new Thickness(-coordX, coordY, 0, 0);
                TBlockNine.Margin   = new Thickness(-dist, 0, 0, 0);
                TBlockTen.Margin    = new Thickness(-coordX, -coordY, 0, 0);
                TBlockEleven.Margin = new Thickness(-coordY, -coordX, 0, 0);

                double txtSize = clockHandler.TxtSize;

                IEnumerable <TextBlock> txtChilden = ParentGrid.Children.OfType <TextBlock>();

                foreach (var child in txtChilden)
                {
                    child.FontSize = txtSize;
                }

                AnalogueClockEllipsis.StrokeThickness = clockHandler.BordorThickness;

                //Center dot for style
                ArmDotEllipsis.Width  = rectangleHour.Height;
                ArmDotEllipsis.Height = rectangleHour.Height;
            }
            catch (Exception error)
            {
                DataValidation.SaveError(error.ToString());
            }
        }