private TextDecorationCollection UnderLinesConverterTo(UnderLines source)
 {
     if (source == UnderLines.BaseLine)
     {
         return(TextDecorations.Baseline);
     }
     else if (source == UnderLines.OverLine)
     {
         return(TextDecorations.OverLine);
     }
     else if (source == UnderLines.Strikethrough)
     {
         return(TextDecorations.Strikethrough);
     }
     else if (source == UnderLines.Underline)
     {
         return(TextDecorations.Underline);
     }
     else
     {
         return(new TextDecorationCollection());
     }
 }
        public FontViewModel(C1FlexSheet flex, IEnumerable <CellRange> cellRange)
        {
            _flex      = flex;
            _cellRange = cellRange;
            foreach (var font in Fonts.SystemFontFamilies)
            {
                if (FontsCollection == null)
                {
                    FontsCollection = new ObservableCollection <FontFamily>();
                }

                FontsCollection.Add(font);
            }

            if (FontsStyles == null)
            {
                FontsStyles = new ObservableCollection <FontStyleFormat>()
                {
                    FontStyleFormat.Normal, FontStyleFormat.Italic, FontStyleFormat.Bold
                }
            }
            ;

            if (FontSize == null)
            {
                FontSize = new ObservableCollection <double>();
            }
            int from = 8; int to = 72;

            for (; from <= to;)
            {
                FontSize.Add(from);
                if (from < 12)
                {
                    from++;
                }
                else
                {
                    from = from + 2;
                }
            }

            if (Underlines == null)
            {
                Underlines = new ObservableCollection <UnderLines>()
                {
                    UnderLines.None, UnderLines.Underline
                }
            }
            ;

            var cell = cellRange.FirstOrDefault();
            var row  = _flex.Rows[cell.TopRow] as ExcelRow;

            if (row != null && cell.IsValid)
            {
                var col = _flex.Columns[cell.Column];
                var cs  = row.GetCellStyle(col);
                cs = cs ?? new CellStyle();

                _origionFont = SelectedFont = cs.FontFamily ?? new FontFamily("Arial");

                _origionFontSize = SelectedFontSize = cs.FontSize ?? 11;

                SelectedFontStyle = FontStyleConvertFrom(cs.FontStyle, cs.FontWeight);
                _origionFontStyle = SelectedFontStyle;

                if (cs.TextDecorations == null || cs.TextDecorations.Count == 0)
                {
                    SelectedUnderLine = UnderLines.None;
                }
                else
                {
                    SelectedUnderLine = UnderLinesConvertFrom(cs.TextDecorations);
                }
                _origionUnderline = SelectedUnderLine;

                var brush = (SolidColorBrush)cs.Foreground;
                _origionColor = SelectedColor = brush == null ? Colors.Transparent : brush.Color;
            }
        }