簡體   English   中英

如何為 AvalonEdit 數字行添加右邊距?

[英]How to add a right margin to AvalonEdit number line?

我在 .Net Framework 4.8 項目中使用 AvalonEdit WPF 控件,在 Windows 10 64 位下使用 Visual Studio 2019。

我需要為行號添加右邊距。 為了理解我需要什么,我附上了一張不言自明的圖片:

在此處輸入圖像描述

接下來是我實際的 xaml 代碼:

<avalonEdit:TextEditor
    Grid.Column="2" Grid.Row="2"
    xmlns:avalonEdit="http://icsharpcode.net/sharpdevelop/avalonedit"
    xmlns:editing="clr-namespace:ICSharpCode.AvalonEdit.Editing;assembly=ICSharpCode.AvalonEdit"
    xmlns:rendering="clr-namespace:ICSharpCode.AvalonEdit.Rendering;assembly=ICSharpCode.AvalonEdit"
    Name="TextEditor"
    FontFamily="Consolas"
    SyntaxHighlighting="C#"
    ShowLineNumbers="True"
    FontSize="10pt" Margin="0">
</avalonEdit:TextEditor>

希望有人能幫我解決這個問題,我花了兩天時間試圖增加這個余量,但無法找到合適的解決方案。 提前致謝。

雖然我評論中的方法可行,但我想到了一種更簡單的方法。 只需從源代碼中復制 TextArea 的樣式並修改它以在包含所有編輯器邊距的 ItemsControl 右側包含一些邊距。 樣式在這里:

https://github.com/icsharpcode/AvalonEdit/blob/395ef8166870e2c6e1f63a7d97ac22e5e646e790/ICSharpCode.AvalonEdit/TextEditor.xaml#L42

這是一個完整的例子:

<Window x:Class="WpfApp1_SO_AvalonEdit.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:avalonEdit="http://icsharpcode.net/sharpdevelop/avalonedit"
    xmlns:editing="clr-namespace:ICSharpCode.AvalonEdit.Editing;assembly=ICSharpCode.AvalonEdit"
    Title="Main Window"
    Width="800"
    Height="450">

<Window.Resources>
    <Style x:Shared="False" TargetType="{x:Type editing:TextArea}">
        <Setter Property="FocusVisualStyle" Value="{x:Null}" />
        <Setter Property="SelectionBrush">
            <Setter.Value>
                <SolidColorBrush Opacity="0.7" Color="#3399FF" />
            </Setter.Value>
        </Setter>
        <Setter Property="SelectionBorder">
            <Setter.Value>
                <Pen>
                    <Pen.Brush>
                        <SolidColorBrush Color="#3399FF" />
                    </Pen.Brush>
                </Pen>
            </Setter.Value>
        </Setter>
        <Setter Property="SelectionForeground">
            <Setter.Value>
                <SolidColorBrush Color="White" />
            </Setter.Value>
        </Setter>

        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type editing:TextArea}">
                    <DockPanel Focusable="False">
                        <ItemsControl Margin="0,0,10,0" Focusable="False" ItemsSource="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=LeftMargins}">
                            <ItemsControl.ItemsPanel>
                                <ItemsPanelTemplate>
                                    <StackPanel Orientation="Horizontal" />
                                </ItemsPanelTemplate>
                            </ItemsControl.ItemsPanel>
                        </ItemsControl>
                        <ContentPresenter Panel.ZIndex="-1" Content="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=TextView}" Focusable="False" />
                    </DockPanel>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</Window.Resources>

<Grid>
    <avalonEdit:TextEditor Name="TextEditor" FontFamily="Consolas" FontSize="10pt" ShowLineNumbers="True" />
</Grid>

在此處輸入圖像描述

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM