Exemple #1
0
        //*** HeaderPanel.Measure -> HeaderItem.UpdateChildren -> 行列改变时 HeaderCellItem.UpdateChildren -> HeaderItem.Measure -> HeaderCellItem.Measure ***//

        public void UpdateChildren()
        {
            // 刷新绑定的Cell
            int row    = OwnRow.Row;
            int column = Column;

            if (CellLayout != null)
            {
                row    = CellLayout.Row;
                column = CellLayout.Column;
            }
            var bindingCell = OwnRow.Owner.CellCache.GetCachedCell(row, column);

            if (bindingCell == null)
            {
                return;
            }

            string text = bindingCell.Text;

            if (string.IsNullOrEmpty(text))
            {
                _tb.ClearValue(TextBlock.TextProperty);
            }
            else
            {
                _tb.Text = text;
                ApplyStyle(bindingCell);
            }
            ApplyState();
        }
        /// <summary>
        /// Layout Text into two lines when width is restricted and determine if a LineBreak occurs.
        /// </summary>
        /// <param name="availableSize">constraint</param>
        /// <param name="secondLinePointer">TextPointer to where a LineBreak occurs</param>
        private void MeasureWithConstraint(Size availableSize, out TextPointer secondLinePointer)
        {
            Debug.Assert(_textBlock1 != null && _textBlock2 != null);

            // Temporarily assign _textBlock1.Text to measure the length it would require
            _textBlock1.Text         = this.Text;
            _textBlock1.TextWrapping = TextWrapping.WrapWithOverflow;
            _textBlock1.Visibility   = Visibility.Visible;

            secondLinePointer = null;

            _textBlock1.Measure(availableSize);

            // Dev11 Bug 65031 - Text: Invariant Assert hit in TextBlock due to loss of precision error
            // Under very rare cases, a loss of precision due to the UseLayoutRounding feature may
            // occur on 64-bit systems that can mean the difference between rounding and not.
            //
            // To work around this, we augment up _textBlock1's DesiredSize.Width by 0.5 pixels
            // before arranging it.  This is safe, because this measure/arrange pass justs determines
            // what should go on the second line of the TwoLineText and is not the actual measure/arrange.
            Size bufferedSize = new Size(_textBlock1.DesiredSize.Width + 0.5,
                                         _textBlock1.DesiredSize.Height);

            _textBlock1.Arrange(new Rect(bufferedSize));

            secondLinePointer = _textBlock1.ContentStart.GetLineStartPosition(1);

            // Clear local value
            _textBlock1.ClearValue(TextBlock.TextWrappingProperty);
        }
 public void DisposeTextBlock(TextBlock textBlock)
 {
     textBlock.ClearValue(TextBlock.FontFamilyProperty);
     textBlock.ClearValue(TextBlock.FontSizeProperty);
     textBlock.ClearValue(TextBlock.TextProperty);
     textBlock.ClearValue(TextBlock.TextWrappingProperty);
     textBlock.ClearValue(TextBlock.ForegroundProperty);
 }
        internal static RadSize MeasureVisual(TextBlock visual)
        {
            visual.ClearValue(TextBlock.WidthProperty);
            visual.ClearValue(TextBlock.HeightProperty);
            var result = IFrameworkElementHelper.Measure(visual, RadCalendar.InfinitySize);

            return(new RadSize(result.Width, result.Height));
        }
 private void DisposeTextBlock(TextBlock textBlock)
 {
     if (textBlock == null)
     {
         return;
     }
     textBlock.ClearValue(TextBlock.FontFamilyProperty);
     textBlock.ClearValue(TextBlock.FontSizeProperty);
     textBlock.ClearValue(TextBlock.TextProperty);
     textBlock.ClearValue(TextBlock.TextWrappingProperty);
     textBlock.ClearValue(TextBlock.ForegroundProperty);
 }
Exemple #6
0
            public void Detach()
            {
                _textBlock.SizeChanged -= UpdateForegroundBrush;

                var parent = VisualTreeHelper.GetParent(_textBlock) as FrameworkElement;

                if (parent != null)
                {
                    parent.SizeChanged -= UpdateForegroundBrush;
                }

                // remove our explicitly set Foreground color
                _textBlock.ClearValue(TextBlock.ForegroundProperty);
                _isAttached = false;
            }
    private static void HighlightSearch(TextBlock textBlock, string value)
    {
        var name          = ((Person)textBlock.DataContext).Name;
        var query         = value.ToUpper();
        var indexOfSearch = name.ToUpper().IndexOf(query, 0);

        if (indexOfSearch < 0)
        {
            return;
        }
        // add normal text first
        var firstText   = name.Substring(0, indexOfSearch).Replace("&", "&amp;");
        var first       = $@"<Span xml:space=""preserve"" xmlns=""{@namespace}"">{firstText}</Span>";
        var firstResult = (Span)XamlReader.Load(first);
        // add the bold text
        var boldText   = name.Substring(indexOfSearch, query.Length).Replace("&", "&amp;");
        var bold       = $@"<Bold xml:space=""preserve"" xmlns=""{@namespace}"">{boldText}</Bold>";
        var boldResult = (Bold)XamlReader.Load(bold);
        // add the rest of the text
        var restStartIndex = indexOfSearch + query.Length;
        var restText       = name.Substring(restStartIndex, name.Length - restStartIndex).Replace("&", "&amp;");
        var rest           = $@"<Span xml:space=""preserve"" xmlns=""{@namespace}"">{restText}</Span>";
        var restResult     = (Span)XamlReader.Load(rest);

        // Clear current textBlock
        textBlock.ClearValue(TextBlock.TextProperty);
        textBlock.Inlines.Clear();
        // Inject to inlines
        textBlock.Inlines.Add(firstResult);
        textBlock.Inlines.Add(boldResult);
        textBlock.Inlines.Add(restResult);
    }
        private static void HtmlContentPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            TextBlock textBlock = d as TextBlock;

            textBlock.ClearValue(TextBlock.TextProperty);
            textBlock.Inlines.Clear();
            textBlock.Inlines.Add(
                new Run {
                Text       = "Описание ",
                FontWeight = FontWeights.Bold
            }
                );

            string formattedText = (string)e.NewValue ?? string.Empty;

            if (string.IsNullOrEmpty(formattedText))
            {
                return;
            }

            formattedText = HtmlEntity.DeEntitize(formattedText);

            var doc = new HtmlDocument();

            doc.LoadHtml(formattedText);

            foreach (var childNode in doc.DocumentNode.ChildNodes)
            {
                ProcessInline(null, childNode, textBlock.Inlines, textBlock);
            }
        }
Exemple #9
0
        private static void FormattedTextPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            // Clear current textBlock
            TextBlock textBlock = d as TextBlock;

            textBlock.ClearValue(TextBlock.TextProperty);
            textBlock.Inlines.Clear();
            // Create new formatted text
            string formattedText = (string)e.NewValue ?? string.Empty;
            string @namespace    = "http://schemas.microsoft.com/winfx/2006/xaml/presentation";

            if (formattedText.Contains("InlineUIContainer"))
            {
                var result = (InlineUIContainer)XamlReader.Parse(formattedText);
                textBlock.Inlines.Add(result);
            }
            else
            {
                formattedText = new string(formattedText.Where(ch => XmlConvert.IsXmlChar(ch)).ToArray());
                formattedText = $@"<Span xml:space=""preserve"" xmlns=""{@namespace}"">{formattedText}</Span>";
                // Inject to inlines
                var result = (Span)XamlReader.Parse(formattedText);
                textBlock.Inlines.Add(result);
            }
        }
Exemple #10
0
        public void TemplatePropertyValuePrecedence()
        {
            Button b;

            try {
                b = (Button)XamlReader.Load(@"
<Button xmlns=""http://schemas.microsoft.com/client/2007"" xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"">
  <Button.Template>
    <ControlTemplate TargetType=""Button"">
      <TextBlock x:Name=""text"" Text=""hi"" Foreground=""Blue""/>
    </ControlTemplate>
  </Button.Template>
</Button>");
            } catch (Exception e) {
                Tester.WriteLine(e.ToString());
                throw e;
            }

            b.ApplyTemplate();

            TextBlock tb = (TextBlock)VisualTreeHelper.GetChild(b, 0);

            Assert.IsTrue(tb.ReadLocalValue(TextBlock.ForegroundProperty) is SolidColorBrush, "1");
            Assert.AreEqual(Colors.Blue, ((SolidColorBrush)tb.ReadLocalValue(TextBlock.ForegroundProperty)).Color, "1.1");

            tb.ClearValue(TextBlock.ForegroundProperty);

            Assert.AreEqual(DependencyProperty.UnsetValue, tb.ReadLocalValue(TextBlock.ForegroundProperty), "2");
            Assert.IsNotNull(tb.GetValue(TextBlock.ForegroundProperty), "2.1");
            Assert.IsTrue(tb.GetValue(TextBlock.ForegroundProperty) is SolidColorBrush, "2.2");
            Assert.AreEqual(Colors.Black, ((SolidColorBrush)tb.GetValue(TextBlock.ForegroundProperty)).Color, "2.3");
        }
        internal override void PrepareCell(GridCellModel cell)
        {
            base.PrepareCell(cell);

            TextBlock tb = cell.Container as TextBlock;

            if (tb == null)
            {
                return;
            }

            if (cell.Value == null)
            {
                tb.ClearValue(TextBlock.TextProperty);
                return;
            }

            string text;

            if (!string.IsNullOrEmpty(this.cellContentFormatCache))
            {
                text = string.Format(CultureInfo.CurrentUICulture, this.cellContentFormatCache, cell.Value);
            }
            else
            {
                text = Convert.ToString(cell.Value, CultureInfo.CurrentUICulture);
            }

            if (tb.Text != text)
            {
                tb.Text = text;
            }
        }
        public void AttachedPropWithNaN()
        {
            var dp2  = DependencyProperty.RegisterAttached("MyAttachedProp2", typeof(double), typeof(TextBlock), PropertyMetadata.Create(double.NaN));
            var dump = Helper.GetDump(() =>
            {
                var tb = new TextBlock();
                tb.ClearValue(dp2);
                return(tb);
            }, new string[] { }, new AttachedProperty[] { new AttachedProperty()
                                                          {
                                                              Name = "MyAttachedProp2", Property = dp2
                                                          } });

            var dumpObject = JObject.Parse(dump);
            var obj        = new JObject {
                { "XamlType", "Windows.UI.Xaml.Controls.TextBlock" },
                { "Clip", null },
                { "FlowDirection", "LeftToRight" },
                { "Foreground", "#FF000000" },
                { "HorizontalAlignment", "Stretch" },
                { "Margin", "0,0,0,0" },
                { "Padding", "0,0,0,0" },
                { "RenderSize", new JArray {
                      0, 0
                  } },
                { "Text", "" },
                { "VerticalAlignment", "Stretch" },
                { "Visibility", "Visible" },
            };

            Assert.AreEqual(dumpObject.ToString(), obj.ToString());
        }
        public void ListBoxItem_Dropping(object sender, DragEventArgs e)
        {
            try
            {
                TextBlock droppedData = e.Data.GetData(typeof(TextBlock)) as TextBlock;
                TextBlock target      = ((ListBoxItem)(sender)).DataContext as TextBlock;

                int removedIdx = ListBox.Items.IndexOf(droppedData);
                int targetIdx  = ListBox.Items.IndexOf(target);

                if (removedIdx < targetIdx)
                {
                    TextBlocks.Insert(targetIdx + 1, droppedData);
                    TextBlocks.RemoveAt(removedIdx);
                }
                else
                {
                    int remIdx = removedIdx + 1;
                    if (TextBlocks.Count + 1 > remIdx)
                    {
                        TextBlocks.Insert(targetIdx, droppedData);
                        TextBlocks.RemoveAt(remIdx);
                    }
                }


                CloseWindow();
                droppedData.ClearValue(EffectProperty);
                Mouse.SetCursor(Cursors.Arrow);
            }
            catch (Exception ex)
            {
                IMethods.WriteToErrorLog("DragAndDrop.cs => ListBoxItem_Dropping", ex.Message, user);
            }
        }
Exemple #14
0
        /// <inheritdoc/>
        public override void PrepareCell(object container, object value, object item)
        {
            base.PrepareCell(container, value, item);

            TextBlock tb = container as TextBlock;

            if (tb == null)
            {
                return;
            }

            if (value == null)
            {
                tb.ClearValue(TextBlock.TextProperty);
                return;
            }

            string text;

            if (!string.IsNullOrEmpty(this.cellContentFormatCache))
            {
                text = string.Format(CultureInfo.CurrentUICulture, this.cellContentFormatCache, value);
            }
            else
            {
                text = Convert.ToString(value, CultureInfo.CurrentUICulture);
            }

            if (tb.Text != text)
            {
                tb.Text = text;
            }
        }
        private static void OnHasAutoToolTipPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            TextBlock textBlock = d as TextBlock;

            if (textBlock == null)
            {
                return;
            }

            if (e.NewValue.Equals(true))
            {
                textBlock.TextTrimming = TextTrimming.CharacterEllipsis;
                //
                // These are a lot of subscriptions for all text blocks in the application.
                // But the performance impact seems to be minimal.
                // We should keep on monitoring the performance; for now, the
                // subscriptions below provide all possible triggers that are needed to
                // update the tooltip on a truncated textblock.
                //
                textBlock.Loaded      += OnPropertyChanged;
                textBlock.SizeChanged += OnPropertyChanged;
                //
                // The text could change while the size doesn't change, but the tooltip still
                // has to be updated, so we need this event to see any change in a databound
                // TextBlock.Text. NOTE: the corresponding binding on the Text property should
                // set: NotifyOnTargetUpdated=True. This can be done on a per case basis.
                //
                textBlock.TargetUpdated += OnPropertyChanged;

                if (textBlock.IsLoaded)
                {
                    ComputeAutoToolTip(textBlock);
                }
            }
            else
            {
                textBlock.ClearValue(TextBlock.TextTrimmingProperty);
                textBlock.ClearValue(ToolTipService.ToolTipProperty);
                textBlock.ClearValue(ToolTipService.ShowOnDisabledProperty);
                textBlock.Loaded        -= OnPropertyChanged;
                textBlock.SizeChanged   -= OnPropertyChanged;
                textBlock.TargetUpdated -= OnPropertyChanged;
                textBlock.Tag            = null;
            }
        }
Exemple #16
0
 public void Refresh(TextBlock v, RowPresenter p)
 {
     if (_scalar.Value == IGNORE)
     {
         v.Foreground = Brushes.LightGray;
     }
     else
     {
         v.ClearValue(ForegroundProperty);
     }
 }
Exemple #17
0
        void HelpTip_Unloaded(object sender, RoutedEventArgs e)
        {
            if (m_gridHelpBox != null)
            {
                m_gridHelpBox.MouseEnter        -= new MouseEventHandler(m_gridHelpBox_MouseEnter);
                m_gridHelpBox.MouseLeave        -= new MouseEventHandler(m_gridHelpBox_MouseLeave);
                m_gridHelpBox.MouseLeftButtonUp -= new MouseButtonEventHandler(m_gridHelpBox_MouseLeftButtonUp);
            }

            if (m_textBlockBody != null)
            {
                m_textBlockBody.ClearValue(TextBlock.TextProperty);
            }
        }
 public void SetHighlightTextBlockTextProperty(object dataItem, TextBlock textBlock)
 {
     if (this.DataMemberBinding != null)
     {
         var content = this.GetCellContent(dataItem);
         if (content != null)
         {
             textBlock.SetValue(TextBlock.TextProperty, string.Format("{0}", content));
         }
     }
     else
     {
         textBlock.ClearValue(TextBlock.TextProperty);
     }
 }
Exemple #19
0
 private void DisposeTextBlock(ref TextBlock textBlock)
 {
     //Clear the dependency properties of TextBlock
     textBlock.ClearValue(TextBlock.TextProperty);
     textBlock.ClearValue(TextBlock.TextWrappingProperty);
     textBlock.ClearValue(TextBlock.FontFamilyProperty);
     textBlock.ClearValue(TextBlock.FontSizeProperty);
     textBlock.ClearValue(TextBlock.ForegroundProperty);
     textBlock.ClearValue(TextBlock.VisibilityProperty);
 }
        void UpdateTextDecorations(TextBlock textBlock)
        {
            if (textBlock == null)
            {
                return;
            }

            if (ExtendedElement.IsStrikeThrough)
            {
                textBlock.TextDecorations = Windows.UI.Text.TextDecorations.Strikethrough;
            }
            else
            {
                textBlock.ClearValue(TextBlock.TextDecorationsProperty);
            }
        }
    private static void FormattedTextPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
    {
        // Clear current textBlock
        TextBlock textBlock = d as TextBlock;

        textBlock.ClearValue(TextBlock.TextProperty);
        textBlock.Inlines.Clear();
        // Create new formatted text
        string formattedText = (string)e.NewValue ?? string.Empty;
        string @namespace    = "http://schemas.microsoft.com/winfx/2006/xaml/presentation";

        formattedText = $@"<Span xml:space=""preserve"" xmlns=""{@namespace}"">{formattedText}</Span>";
        // Inject to inlines
        var result = (Span)XamlReader.Load(formattedText);

        textBlock.Inlines.Add(result);
    }
Exemple #22
0
        internal void OnIsVerticalTitleChanged()
        {
            if (!_owner.ShowTitle || _tbTitle == null)
            {
                return;
            }

            if (_owner.IsVerticalTitle)
            {
                _tbTitle.TextWrapping = TextWrapping.Wrap;
                _tbTitle.Width        = 15;
            }
            else
            {
                _tbTitle.TextWrapping = TextWrapping.NoWrap;
                _tbTitle.ClearValue(WidthProperty);
            }
        }
Exemple #23
0
        protected override void ClearSearchCell(DataColumnBase column, object record)
        {
            if (column.GridColumn != null && string.IsNullOrEmpty(SearchText) && column.GridColumn.CellTemplate != null)
            {
                TextBlock[] textControls = FindObjectInVisualTreeDown <TextBlock>(column.ColumnElement).ToArray();
                if (textControls.Any())
                {
                    TextBlock textBlock = textControls.First();
                    if (textBlock != null && textBlock.Inlines.Count > 1)
                    {
                        textBlock.ClearValue(TextBlock.TextProperty);
                        return;
                    }
                }
            }

            base.ClearSearchCell(column, record);
        }
Exemple #24
0
        private static void ColorTextblockBackground(TextBlock textBlock, string value, string name)
        {
            var stringArray = name.Split(new string[] { value }, StringSplitOptions.None);
            var laststring  = stringArray.Last();

            textBlock.ClearValue(TextBlock.TextProperty);
            textBlock.Inlines.Clear();
            foreach (var item in stringArray)
            {
                if (item == laststring)
                {
                    textBlock.Inlines.Add(item);
                    continue;
                }
                textBlock.Inlines.Add(item);
                textBlock.Inlines.Add(new Run(value)
                {
                    Background = Brushes.OrangeRed
                });
            }
        }
Exemple #25
0
        public void SettingTextNeverCreatesMoreThanOneRun()
        {
            TextBlock tb = new TextBlock();
            string    text;
            Run       run;

            tb.Text = "this is line 1\rthis is line 2";
            run     = (Run)tb.Inlines[0];
            Assert.AreEqual(1, tb.Inlines.Count, "1. Setting Text property should never create more than 1 Run");
            Assert.AreEqual("this is line 1\rthis is line 2", run.Text, "1. The Run's Text should remain unchanged");

            tb.Text = "this is line 1\nthis is line 2";
            run     = (Run)tb.Inlines[0];
            Assert.AreEqual(1, tb.Inlines.Count, "2. Setting Text property should never create more than 1 Run");
            Assert.AreEqual("this is line 1\nthis is line 2", run.Text, "2. The Run's Text should remain unchanged");

            tb.Text = "this is line 1\r\nthis is line 2";
            run     = (Run)tb.Inlines[0];
            Assert.AreEqual(1, tb.Inlines.Count, "3. Setting Text property should never create more than 1 Run");
            Assert.AreEqual("this is line 1\r\nthis is line 2", run.Text, "3. The Run's Text should remain unchanged");

            // now try using the exact same line separator that LineBreak maps to
            tb.Inlines.Clear();
            run.Text = "this is line 1";
            tb.Inlines.Add(run);
            tb.Inlines.Add(new LineBreak());
            run      = new Run();
            run.Text = "this is line 2";
            tb.Inlines.Add(run);

            text = tb.Text;
            tb.ClearValue(TextBlock.TextProperty);

            tb.Text = text;
            run     = (Run)tb.Inlines[0];
            Assert.AreEqual(1, tb.Inlines.Count, "4. Setting Text property should never create more than 1 Run");
            Assert.AreEqual(text, run.Text, "4. The Run's Text should remain unchanged");
        }
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            TextBlock textblock = value as TextBlock;

            string[] strs = ((string)parameter).Split(' ');

            textblock.ClearValue(TextBlock.TextProperty);
            foreach (string str in strs)
            {
                if (str == "Text")
                {
                    textblock.Inlines.Add(new Run(str)
                    {
                        FontStyle = FontStyles.Italic, TextDecorations = TextDecorations.Underline
                    });
                }
                else
                {
                    textblock.Inlines.Add(new Run(str));
                }
            }
            return(null);
        }
Exemple #27
0
        //*** CellsPanel.Measure -> RowsLayer.Measure -> RowItem.UpdateChildren -> 行列改变时 CellItem.UpdateChildren -> RowItem.Measure -> CellItem.Measure ***//

        public void UpdateChildren()
        {
            // 刷新绑定的Cell
            int row    = OwnRow.Row;
            int column = Column;

            if (CellLayout != null)
            {
                row    = CellLayout.Row;
                column = CellLayout.Column;
            }
            BindingCell = OwnRow.OwnPanel.CellCache.GetCachedCell(row, column);
            if (BindingCell == null)
            {
                return;
            }

            Background = BindingCell.ActualBackground;
            var       excel = Excel;
            Worksheet sheet = BindingCell.Worksheet;

            // 迷你图
            Sparkline sparkline = sheet.GetSparkline(row, column);

            if (_sparkInfo != sparkline)
            {
                SparkLine = sparkline;
                SynSparklineView();
            }

            // 收集所有DrawingObject
            List <DrawingObject> list = new List <DrawingObject>();

            DrawingObject[] objArray = sheet.GetDrawingObject(row, column, 1, 1);
            if ((objArray != null) && (objArray.Length > 0))
            {
                list.AddRange(objArray);
            }

            IDrawingObjectProvider drawingObjectProvider = DrawingObjectManager.GetDrawingObjectProvider(excel);

            if (drawingObjectProvider != null)
            {
                DrawingObject[] objArray2 = drawingObjectProvider.GetDrawingObjects(sheet, row, column, 1, 1);
                if ((objArray2 != null) && (objArray2.Length > 0))
                {
                    list.AddRange(objArray2);
                }
            }

            _dataBarObject       = null;
            _iconObject          = null;
            _customDrawingObject = null;
            if (list.Count > 0)
            {
                foreach (DrawingObject obj in list)
                {
                    if (obj is DataBarDrawingObject bar)
                    {
                        _dataBarObject = bar;
                    }
                    else if (obj is IconDrawingObject icon)
                    {
                        _iconObject = icon;
                    }
                    else if (obj is CustomDrawingObject cust)
                    {
                        _customDrawingObject = cust;
                    }
                }
            }

            bool noBarIcon = SynContitionalView();
            bool noCust    = SynCustomDrawingObjectView();

            if (sparkline == null && noBarIcon && noCust && !string.IsNullOrEmpty(BindingCell.Text))
            {
                _tb.Text = BindingCell.Text;
                ApplyStyle();
            }
            else
            {
                _tb.ClearValue(TextBlock.TextProperty);
            }
            SynStrikethroughView();

#if UWP || WASM
            // 手机上体验不好
            if (!excel.IsTouching)
            {
                FilterButtonInfo info = excel.GetFilterButtonInfo(row, column, BindingCell.SheetArea);
                if (info != FilterButtonInfo)
                {
                    FilterButtonInfo = info;
                    SynFilterButton();
                }
            }
#endif
        }
Exemple #28
0
        public static void SetRichFormatText(this TextBlock textBlock, string text)
        {
            if (textBlock == null)
            {
                return;
            }
            string[] strs = text.Split('[');
            textBlock.ClearValue(TextBlock.TextProperty);
            var          solidColorBrush = textBlock.Foreground as SolidColorBrush;
            List <Color> colors          = new List <Color> {
                Colors.Black
            };
            List <double> fontSizes = new List <double> {
                textBlock.FontSize
            };
            List <FontWeight> weights = new List <FontWeight> {
                textBlock.FontWeight
            };

            if (solidColorBrush != null)
            {
                colors.Add(solidColorBrush.Color);
            }
            foreach (string str in strs)
            {
                string[] parts = str.Split(']');
                string   txt;
                if (parts.Length > 1)
                {
                    txt = parts[1];
                    string   format = parts[0];
                    string[] fParts = format.Split('=');
                    if (fParts.Length == 1)//end tag
                    {
                        switch (fParts[0])
                        {
                        case "color":
                            colors.RemoveAt(colors.Count - 1);
                            break;

                        case "weight":
                            weights.RemoveAt(weights.Count - 1);
                            break;

                        case "fsize":
                            fontSizes.RemoveAt(fontSizes.Count - 1);
                            break;
                        }
                    }
                    else
                    {
                        switch (fParts[0])
                        {
                        case "color":
                            string color    = fParts[1];
                            var    colorObj = ColorConverter.ConvertFromString(color);

                            if (colorObj != null)
                            {
                                colors.Add((Color)colorObj);
                            }
                            break;

                        case "weight":
                            var fontWeight = new FontWeightConverter().ConvertFromString(fParts[1]);
                            if (fontWeight != null)
                            {
                                weights.Add((FontWeight)fontWeight);
                            }
                            break;

                        case "fsize":
                            double fontSize = fontSizes.Last();
                            string fSize    = fParts[1];
                            if (fParts[1].StartsWith("+") || fParts[1].StartsWith("-"))
                            {
                                fSize = fParts[1].Substring(1);
                            }
                            var ok = double.TryParse(fSize, out fontSize);

                            if (ok)
                            {
                                if (fParts[1].StartsWith("+"))
                                {
                                    fontSize = fontSizes.Last() + fontSize;
                                }
                                if (fParts[1].StartsWith("-"))
                                {
                                    fontSize = fontSizes.Last() - fontSize;
                                }
                                fontSizes.Add(fontSize);
                            }

                            break;

                        case "image":
                            string imageUrl = fParts[1];
                            AddImage(textBlock, imageUrl, 1.2, BaselineAlignment.Center);
                            break;
                        }
                    }
                }
                else
                {
                    txt = parts[0];
                }
                if (!string.IsNullOrEmpty(txt))
                {
                    textBlock.Inlines.Add(new Run(txt)
                    {
                        Foreground        = new SolidColorBrush(colors.Last()),
                        FontWeight        = weights.Last(),
                        FontSize          = fontSizes.Last(),
                        BaselineAlignment = BaselineAlignment.Center
                    });
                }
            }
        }
Exemple #29
0
 internal void UpdateChartTitle()
 {
     if (ChartTitle != null)
     {
         _titleFrame.StrokeDashArray = StrokeDashHelper.GetStrokeDashes(ChartTitle.StrokeDashType);
         double strokeThickness = ChartTitle.StrokeThickness;
         if (strokeThickness > 0.0)
         {
             if ((_parentView != null) && (_parentView.ParentViewport != null))
             {
                 strokeThickness *= _parentView.ParentViewport.Excel.ZoomFactor;
             }
             _titleFrame.StrokeThickness = strokeThickness;
         }
         else
         {
             _titleFrame.StrokeThickness = 0.0;
         }
         Brush actualStroke = ChartTitle.ActualStroke;
         if (actualStroke != null)
         {
             _titleFrame.Stroke = actualStroke;
         }
         else
         {
             _titleFrame.Stroke = new SolidColorBrush(Colors.Transparent);
         }
         Brush actualFill = ChartTitle.ActualFill;
         if (actualFill != null)
         {
             _titleFrame.Fill = actualFill;
         }
         else
         {
             _titleFrame.Fill = new SolidColorBrush(Colors.Transparent);
         }
         _titleContent.Text = ChartTitle.Text;
         FontFamily actualFontFamily = ChartTitle.ActualFontFamily;
         if (actualFontFamily == null)
         {
             actualFontFamily = Utility.DefaultFontFamily;
         }
         _titleContent.FontFamily = actualFontFamily;
         double actualFontSize = ChartTitle.ActualFontSize;
         if ((_parentView.ParentViewport != null) && (_parentView.ParentViewport.Excel != null))
         {
             actualFontSize *= _parentView.ParentViewport.Excel.ZoomFactor;
         }
         if (actualFontSize > 0.0)
         {
             _titleContent.FontSize = actualFontSize;
         }
         _titleContent.FontStretch = ChartTitle.ActualFontStretch;
         _titleContent.FontStyle   = ChartTitle.ActualFontStyle;
         _titleContent.FontWeight  = ChartTitle.ActualFontWeight;
         Brush actualForeground = ChartTitle.ActualForeground;
         if (actualForeground != null)
         {
             _titleContent.Foreground = actualForeground;
         }
         else
         {
             _titleContent.ClearValue(TextBlock.ForegroundProperty);
         }
     }
     else
     {
         _titleFrame.Stroke = null;
         _titleFrame.Fill   = null;
         _titleContent.ClearValue(TextBlock.TextProperty);
     }
 }
Exemple #30
0
 private void Clear()
 {
     text.ClearValue(ForegroundProperty);
     text.ClearValue(TextBlock.TextProperty);
 }