C# WPF工具包-DataGrid控件中存在绑定问题
首先,我必须说,这看起来像是很多代码,但它很容易阅读。 我正试图整理一些东西,结果得到了: 如您所见,数字、描述、行和列似乎已被复制 在我的主窗体设计器上,我有:C# WPF工具包-DataGrid控件中存在绑定问题,c#,datagrid,binding,wpftoolkit,C#,Datagrid,Binding,Wpftoolkit,首先,我必须说,这看起来像是很多代码,但它很容易阅读。 我正试图整理一些东西,结果得到了: 如您所见,数字、描述、行和列似乎已被复制 在我的主窗体设计器上,我有: <Window x:Class="Visual_Command_Line.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/win
<Window x:Class="Visual_Command_Line.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:Visual_Command_Line"
xmlns:dg="http://schemas.microsoft.com/wpf/2008/toolkit"
Title="Visual Command Line" MinHeight="750" MinWidth="900" Loaded="Window_Loaded" Icon="/Visual_Command_Line;component/Resources/icon16x16.ico" WindowStartupLocation="CenterScreen" WindowState="Maximized" Closing="Window_Closing">
<Window.Resources>
<local:ErrorListCollection x:Key="ErrorList" />
</Window.Resources>
<dg:DataGrid Name="DataGrid_ErrorList" IsReadOnly="True" CanUserAddRows="False" CanUserDeleteRows="False" CanUserResizeRows="False" CanUserSortColumns="False" ItemsSource="{Binding Source={StaticResource ErrorList}}">
<dg:DataGrid.Columns>
<dg:DataGridTextColumn Binding="{Binding Path=GetNumber}" Header="" />
<dg:DataGridTextColumn Binding="{Binding Path=GetDescription}" Header="Description" Width="10*" />
<dg:DataGridTextColumn Binding="{Binding Path=GetLine}" Header="Line" Width="*" />
<dg:DataGridTextColumn Binding="{Binding Path=GetColumn}" Header="Column" Width="*" />
</dg:DataGrid.Columns>
</dg:DataGrid>
</Grid>
((ErrorListCollection)this.FindResource("ErrorList")).RenewErrorList(((TabDocument)dockManager.ActiveDocument).currentAnalizedLine);
class ErrorListCollection : ObservableCollection<DebugError>
{
public ErrorListCollection()
{
}
public void RenewErrorList(AnalizedLine al) //also all lines
{
this.Clear();
int currentAnalizedLine_lineNumber = al.lineNumber;
int errNumber = 1;
foreach (Boundaries b in al.GetBoundaries)
{
if (b.dataType == Boundaries.DataType.Unknown)
{
this.Add(new DebugError(errNumber, "d", "l", "c"));
errNumber++;
}
}
}
}
class DebugError
{
private int Number;
private string Description;
private string Line;
private string Column;
public int GetNumber
{
get
{
return this.Number;
}
}
public string GetDescription
{
get
{
return this.Description;
}
}
public string GetLine
{
get
{
return this.Line;
}
}
public string GetColumn
{
get
{
return this.Column;
}
}
public DebugError(int Number, string Description, string Line, string Column)
{
this.Number = Number;
this.Description = Description;
this.Line = Line;
this.Column = Column;
}
}
这是ErrorListCollection类:
<Window x:Class="Visual_Command_Line.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:Visual_Command_Line"
xmlns:dg="http://schemas.microsoft.com/wpf/2008/toolkit"
Title="Visual Command Line" MinHeight="750" MinWidth="900" Loaded="Window_Loaded" Icon="/Visual_Command_Line;component/Resources/icon16x16.ico" WindowStartupLocation="CenterScreen" WindowState="Maximized" Closing="Window_Closing">
<Window.Resources>
<local:ErrorListCollection x:Key="ErrorList" />
</Window.Resources>
<dg:DataGrid Name="DataGrid_ErrorList" IsReadOnly="True" CanUserAddRows="False" CanUserDeleteRows="False" CanUserResizeRows="False" CanUserSortColumns="False" ItemsSource="{Binding Source={StaticResource ErrorList}}">
<dg:DataGrid.Columns>
<dg:DataGridTextColumn Binding="{Binding Path=GetNumber}" Header="" />
<dg:DataGridTextColumn Binding="{Binding Path=GetDescription}" Header="Description" Width="10*" />
<dg:DataGridTextColumn Binding="{Binding Path=GetLine}" Header="Line" Width="*" />
<dg:DataGridTextColumn Binding="{Binding Path=GetColumn}" Header="Column" Width="*" />
</dg:DataGrid.Columns>
</dg:DataGrid>
</Grid>
((ErrorListCollection)this.FindResource("ErrorList")).RenewErrorList(((TabDocument)dockManager.ActiveDocument).currentAnalizedLine);
class ErrorListCollection : ObservableCollection<DebugError>
{
public ErrorListCollection()
{
}
public void RenewErrorList(AnalizedLine al) //also all lines
{
this.Clear();
int currentAnalizedLine_lineNumber = al.lineNumber;
int errNumber = 1;
foreach (Boundaries b in al.GetBoundaries)
{
if (b.dataType == Boundaries.DataType.Unknown)
{
this.Add(new DebugError(errNumber, "d", "l", "c"));
errNumber++;
}
}
}
}
class DebugError
{
private int Number;
private string Description;
private string Line;
private string Column;
public int GetNumber
{
get
{
return this.Number;
}
}
public string GetDescription
{
get
{
return this.Description;
}
}
public string GetLine
{
get
{
return this.Line;
}
}
public string GetColumn
{
get
{
return this.Column;
}
}
public DebugError(int Number, string Description, string Line, string Column)
{
this.Number = Number;
this.Description = Description;
this.Line = Line;
this.Column = Column;
}
}
如何修复这些重复项?尝试添加
AutoGenerateColumn=“False”
尝试设置AutoGenerateColumns=“False”
您还可以稍微简化DebugError类:
class DebugError
{
public int Number { get; private set; }
public string Description { get; private set; }
public string Line { get; private set; }
public string Column { get; private set; }
public DebugError(int number, string description, string line, string column)
{
Number = number;
Description = description;
Line = line;
Column = column;
}
}
哦,我真不敢相信。这件事我已经做了两个小时了。该死:(,无论如何,谢谢。我也会去掉构造函数,但为了连续性,我把它留在了。你怎么去掉构造函数呢?一个对象初始值设定项,它是一个C#3.0特性(像自动道具)。类似这样的东西:var de=new DebugError{Number=0,Description=“TACO”,Line=“Three?”,Column=“Food Awesomeness”};嘿,等等,把它作为一个问题发出来!谢谢你的帮助,里奇,虽然我认为这不值得问一个问题,但我会用你说的一切:)