C#应用程序中是否有标记栏组件可用于我的应用程序?作为标记栏我的意思是这样ReSharper的添加到Visual Studio:C#应用程序的标记栏?
类似的东西,(左边栏)又如:
编辑:我发现非免费的组件供java http://www.sideofsoftware.com/marker_bar/doc/sos/marker/JMarkerBar.html什么是我想要做的。它不适合我,但也许它有助于某人。
C#应用程序中是否有标记栏组件可用于我的应用程序?作为标记栏我的意思是这样ReSharper的添加到Visual Studio:C#应用程序的标记栏?
类似的东西,(左边栏)又如:
编辑:我发现非免费的组件供java http://www.sideofsoftware.com/marker_bar/doc/sos/marker/JMarkerBar.html什么是我想要做的。它不适合我,但也许它有助于某人。
在WPF中,酒吧有点像一个ListBox,只是以不同的方式为每一行文本显示1像素的高行。线的状态会影响线的颜色,并选择一条线会引起文本框可以响应的SelectionChanged事件。
让我知道你是否希望我展示原型。
编辑
这里去。您可以单击/选择栏中的某一行,然后文本框将滚动到该行。
仍然补充:
怎么办时,行数是大了吧?
不同的方式来显示栏中当前行:
将选定的线条保持在与文本框中插入符号同步的位置。
...
这些都可以解决,但在很大程度上取决于你想要什么。这应该让你开始。
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>
<ListBox ItemsSource="{Binding}"
SelectionChanged="ListBox_SelectionChanged">
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<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>
</ListBox.ItemContainerStyle>
<ListBox.ItemTemplate>
<DataTemplate>
<Rectangle StrokeThickness="0"
Stroke="Green"
Fill="{Binding Status, Converter={StaticResource statusToBrushConverter}}"
Height="1"
HorizontalAlignment="Stretch" />
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<TextBox AcceptsReturn="True"
Grid.Column="1"
x:Name="codeBox" />
</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;
codeBox.Text = String.Join("\n", from line in lines
select line.Line);
}
private void ListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
var selectedLine = ((ListBox)sender).SelectedIndex;
codeBox.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, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}
}
你可以使用面板上的Graphics类,以自己绘制它。
http://msdn.microsoft.com/en-us/library/system.drawing.graphics.aspx
(我不会用条形图作为泰奥曼Soygul建议,这是滥用成分的东西,他们不应该做的。同样的,由艾尔诺列表框中的想法。列表框用于表示由文本行,而不是标记栏。)
那当然是最好的解决方案,但我还没有使用它,所以不知道如何做到这一点。 – hs2d 2011-05-21 20:20:08
WPF中的ListBoxes可以显示任何你喜欢的东西。图片,文字,形状,线条。为什么要从头开始构建你所需要的一切,甚至不需要滥用列表框。实际上,ListBox正在显示文本,但只是使用不同的表示。 – 2011-05-21 21:30:39
您使用的是什么技术? Winforms,WPF,...? – 2011-05-21 18:27:41
那么,只是做研究,所以没有真正希望使用什么。可以是其中的任何一种。 – hs2d 2011-05-21 18:30:56
在WPF中创建一个会很困难(对我而言),但是很大程度上取决于你想要的功能类型(例如,它应该是可点击的吗?) – 2011-05-21 18:36:18