首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >WPF工具包-在DataGrid控件中有问题绑定

WPF工具包-在DataGrid控件中有问题绑定
EN

Stack Overflow用户
提问于 2011-03-03 01:27:48
回答 2查看 866关注 0票数 4

首先,我必须说,这看起来可能是很多代码,但它很容易阅读。我试图把一些东西绑起来,结果我得到了这样的结果:

http://img694.imageshack.us/f/28475988.jpg/

如您所见,数字、描述、行和列似乎已被复制。

我的主表单设计器上的

代码语言:javascript
复制
<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>

当主表单加载时,

代码语言:javascript
复制
((ErrorListCollection)this.FindResource("ErrorList")).RenewErrorList(((TabDocument)dockManager.ActiveDocument).currentAnalizedLine);

这里是ErrorListCollection类:

代码语言:javascript
复制
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++;
            }
        }
    }
}

DebugError类:

代码语言:javascript
复制
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;
    }
}

如何修复这些副本?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2011-03-03 01:32:16

尝试添加AutoGenerateColumn="False"

代码语言:javascript
复制
<dg:DataGrid Name="DataGrid_ErrorList" AutoGenerateColumns="False"
票数 6
EN

Stack Overflow用户

发布于 2011-03-03 01:36:06

尝试设置AutoGenerateColumns="False“

您也可以简化您的DebugError类:

代码语言:javascript
复制
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;
    }
}
票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5175608

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档