C# · 12月 30, 2021

C#应用程序的标记栏?

C#应用程序是否有标记栏组件,我可以在我的应用程序中使用什么?作为标记栏我的意思是像ReSharper添加到Visual Studio:

类似的东西的另一个例子(左侧的栏):

编辑:我发现java http://www.sideofsoftware.com/marker_bar/doc/sos/marker/JMarkerBar.html的非免费组件正是我想要做的.它不适合我,但也许它有助于某人.

解决方法 在WPF中,该栏有点像一个List@R_197_2419@,只是一种不同的方法,可以为每行文本显示一个1像素的高线.该行的状态将影响该行的颜色,并选择一行将引发该文本框可以响应的SelectionChanged事件.

让我知道,如果你要我展示一个原型.

编辑

开始.您可以点击/选择一条线条,文本框将滚动到该行.

还要补充:

>当线条的数量是大的时候该怎么做?@H_404_19@>以不同的方式显示当前在线上的行?@H_404_19@>将文本框中的插入符号与选定的行保持同步.@H_404_19@> …

这些可以解决,但很大程度上取决于你想要的.这应该让你开始.

XAML:

<Window x:Class=”WpfApplication2.MainWindow” xmlns=”http://schemas.microsoft.com/winfx/2006/xaml/presentation” xmlns:x=”http://schemas.microsoft.com/winfx/2006/xaml” xmlns:local=”clr-namespace:WpfApplication2″ Title=”MainWindow” Height=”350″ Width=”525″> <Window.Resources> <local:StatusToBrushConverter x:Key=”statusToBrushConverter” /> </Window.Resources> <Grid> <Grid.ColumnDeFinitions> <ColumnDeFinition Width=”30″ /> <ColumnDeFinition /> </Grid.ColumnDeFinitions> <List@R_197_2419@ ItemsSource=”{Binding}” SelectionChanged=”List@R_197_2419@_SelectionChanged”> <List@R_197_2419@.ItemContainerStyle> <Style TargetType=”List@R_197_2419@Item”> <Setter Property=”HorizontalContentAlignment” Value=”Stretch” /> <Setter Property=”Opacity” Value=”0.5″ /> <Setter Property=”MaxHeight” Value=”1″ /> <Setter Property=”MinHeight” Value=”1″ /> <Style.Triggers> <Trigger Property=”IsSelected” Value=”True”> <Trigger.Setters> <Setter Property=”Opacity” Value=”1.0″ /> </Trigger.Setters> </Trigger> </Style.Triggers> </Style> </List@R_197_2419@.ItemContainerStyle> <List@R_197_2419@.ItemTemplate> <DataTemplate> <Rectangle strokeThickness=”0″ stroke=”Green” Fill=”{Binding Status,Converter={StaticResource statusToBrushConverter}}” Height=”1″ HorizontalAlignment=”Stretch” /> </DataTemplate> </List@R_197_2419@.ItemTemplate> </List@R_197_2419@> <Text@R_197_2419@ AcceptsReturn=”True” Grid.Column=”1″ x:Name=”code@R_197_2419@” /> </Grid></Window>

C#:

using System;using System.Collections.ObjectModel;using System.ComponentModel;using System.Linq;using System.Windows;using System.Windows.Controls;namespace WpfApplication2{ public partial class MainWindow : Window { private CodeLines lines; public MainWindow() { InitializeComponent(); lines = new CodeLines(); Random random = new Random(); for (int i = 0; i < 200; i++) { lines.Add(new CodeLine { Status = (VersionStatus)random.Next(0,5),Line = “Line ” + i }); } this.DataContext = lines; code@R_197_2419@.Text = String.Join(“\n”,from line in lines select line.Line); } private void List@R_197_2419@_SelectionChanged(object sender,SelectionChangedEventArgs e) { var selectedLine = ((List@R_197_2419@)sender).SelectedIndex; code@R_197_2419@.ScrollToLine(selectedLine); } } public enum VersionStatus { Original,Added,Modified,Deleted } public class CodeLine : INotifyPropertyChanged { private VersionStatus status; public VersionStatus Status { get { return status; } set { if (status != value) { status = value; OnPropertyChanged(“Status”); } } } private string line; public string Line { get { return line; } set { if (line != value) { line = value; OnPropertyChanged(“Line”); } } } public event PropertyChangedEventHandler PropertyChanged; protected void OnPropertyChanged(string propertyName) { var p = PropertyChanged; if (p != null) { p(this,new PropertyChangedEventArgs(propertyName)); } } } public class CodeLines : ObservableCollection<CodeLine> { } class StatusToBrushConverter : IValueConverter { public object Convert(object value,Type targetType,object parameter,System.Globalization.CultureInfo culture) { var status = (VersionStatus)value; switch (status) { case VersionStatus.Original: return Brushes.Green; case VersionStatus.Added: return Brushes.Blue; case VersionStatus.Modified: return Brushes.Yellow; case VersionStatus.Deleted: return Brushes.Red; default: return DependencyProperty.UnsetValue; } } public object ConvertBack(object value,System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } }}