Пример #1
0
        static void OnShowLineNumbersChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            TextEditor editor      = (TextEditor)d;
            var        leftMargins = editor.TextArea.LeftMargins;

            if ((bool)e.NewValue)
            {
                leftMargins.Insert(0, new LineNumberMargin());
                leftMargins.Insert(1, DottedLineMargin.Create());
            }
            else
            {
                for (int i = 0; i < leftMargins.Count; i++)
                {
                    if (leftMargins[i] is LineNumberMargin)
                    {
                        leftMargins.RemoveAt(i);
                        if (i < leftMargins.Count && DottedLineMargin.IsDottedLineMargin(leftMargins[i]))
                        {
                            leftMargins.RemoveAt(i);
                        }
                        break;
                    }
                }
            }
        }
Пример #2
0
        private static void OnShowLineNumbersChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            TextEditor editor      = (TextEditor)d;
            var        leftMargins = editor.TextArea.LeftMargins;

            if ((bool)e.NewValue)
            {
                LineNumberMargin lineNumbers = new LineNumberMargin();
                Line             line        = (Line)DottedLineMargin.Create();
                leftMargins.Insert(0, lineNumbers);
                leftMargins.Insert(1, line);
                var lineNumbersForeground = new Binding("LineNumbersForeground")
                {
                    Source = editor
                };
                line.SetBinding(Line.StrokeProperty, lineNumbersForeground);
                lineNumbers.SetBinding(Control.ForegroundProperty, lineNumbersForeground);
            }
            else
            {
                for (int i = 0; i < leftMargins.Count; i++)
                {
                    if (leftMargins[i] is LineNumberMargin)
                    {
                        leftMargins.RemoveAt(i);
                        if (i < leftMargins.Count && DottedLineMargin.IsDottedLineMargin(leftMargins[i]))
                        {
                            leftMargins.RemoveAt(i);
                        }
                        break;
                    }
                }
            }
        }
Пример #3
0
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var leftMargins = (ObservableCollection <UIElement>)value;

            return(leftMargins.Where(lm => !DottedLineMargin.IsDottedLineMargin(lm)));
        }