public static ToolTip CreateToolTip(string header, LuniSolarDate <VietnameseLocalInfoProvider> date,
                                            string decorator, bool isSymbolicDecorator, double hueValue = -1,
                                            bool overideContentForeground = false,
                                            int maxWidth = 400, int padding = 3)
        {
            Grid contentGrid = new Grid();

            contentGrid.ColumnDefinitions.Add(new ColumnDefinition());
            contentGrid.ColumnDefinitions.Add(new ColumnDefinition());


            string[] columnContent =
            {
                string.Format(new System.Globalization.CultureInfo(_cultureInfoTag), "{0:d} ({0:dddd})", date.SolarDate),
                string.Format("Ngày {0} tháng {1} năm {2}",                          date.Day,           date.MonthShortName,date.Year),
                date.YearName,                                                       date.MonthLongName, date.DayName,       date.SolarTerm
            };
            for (int i = 0; i < _columnHeader.Length; i++)
            {
                contentGrid.RowDefinitions.Add(new RowDefinition());
                TextBlock headerCell = new TextBlock
                {
                    HorizontalAlignment = HorizontalAlignment.Right,
                    Text = _columnHeader[i],
                };
                TextBlock contentCell = new TextBlock
                {
                    HorizontalAlignment = HorizontalAlignment.Stretch,
                    TextAlignment       = TextAlignment.Left,
                    TextWrapping        = TextWrapping.Wrap,
                    Text       = columnContent[i],
                    FontWeight = FontWeights.SemiBold,
                };
                Grid.SetRow(headerCell, i);
                Grid.SetRow(contentCell, i);
                Grid.SetColumn(headerCell, 0);
                Grid.SetColumn(contentCell, 1);
                contentGrid.Children.Add(headerCell);
                contentGrid.Children.Add(contentCell);
            }
            ContentControl cc = new ContentControl
            {
                Content = contentGrid
            };

            return(ToolTipWithHeader.CreateToolTip(header, null, cc,
                                                   decorator, isSymbolicDecorator, hueValue, overideContentForeground, maxWidth, padding));
        }
예제 #2
0
        private static Rectangle CreateRectangle(int solarTermIndex, DateTime date, string description, FontFamily fontFamily)
        {
            if (solarTermIndex >= 24)
            {
                solarTermIndex = solarTermIndex % 24;
            }

            int   H = GetHueValue(solarTermIndex);
            Color normalBackground    = Helper.ColorFromHSV(H, 0.6, 1);
            Color zeroAlphaBackground = Color.FromArgb(0, normalBackground.R, normalBackground.G, normalBackground.B);
            Color mouseOverBakground  = Helper.ColorFromHSV(H, 0.6, 0.8);

            GradientStopCollection normalTermGradient = new GradientStopCollection
            {
                new GradientStop(zeroAlphaBackground, 0),
                new GradientStop(zeroAlphaBackground, 0.45),
                new GradientStop(normalBackground, 0.45),
                new GradientStop(normalBackground, 0.65),
                new GradientStop(zeroAlphaBackground, 0.65),
                new GradientStop(zeroAlphaBackground, 1)
            };
            LinearGradientBrush normalTermBrush = new LinearGradientBrush(normalTermGradient, 90);

            GradientStopCollection currentTermGradient = new GradientStopCollection
            {
                new GradientStop(zeroAlphaBackground, 0),
                new GradientStop(zeroAlphaBackground, 0.35),
                new GradientStop(normalBackground, 0.35),
                new GradientStop(normalBackground, 0.75),
                new GradientStop(zeroAlphaBackground, 0.75),
                new GradientStop(zeroAlphaBackground, 1)
            };
            LinearGradientBrush currentTermBrush = new LinearGradientBrush(currentTermGradient, 90);

            SolidColorBrush hoverBrush = new SolidColorBrush(mouseOverBakground);

            Rectangle rectangle = new Rectangle()
            {
                Height              = 10,
                VerticalAlignment   = VerticalAlignment.Center,
                HorizontalAlignment = HorizontalAlignment.Stretch,
                ToolTip             = ToolTipWithHeader.CreateToolTip(
                    SolarTermsVietnamese[solarTermIndex],
                    "Từ ngày " + date.ToString("dd/MM/yyyy HH:mm ± 15\\'"),
                    null, null, false, GetHueValue(solarTermIndex), true, 200, 3, 12),
            };

            rectangle.Style = new Style()
            {
                Triggers = { new Trigger()
                             {
                                 Property = Rectangle.NameProperty, Value = CURRENT_TERM_LABEL,
                                 Setters  =  { new Setter()
                                               {
                                                   Property = Rectangle.FillProperty, Value = currentTermBrush,
                                               }, },
                             },
                             new Trigger()
                             {
                                 Property = Rectangle.IsMouseOverProperty, Value = true,
                                 Setters  =  { new Setter()
                                               {
                                                   Property = Rectangle.FillProperty, Value = hoverBrush,
                                               }, },
                             }, },

                Setters = { new Setter()
                            {
                                Property = Rectangle.FillProperty, Value = normalTermBrush,
                            } },
            };

            return(rectangle);
        }