使用MVVMLight设置绑定后的WPF Datagrid绑定错误

时间:2016-05-24 16:46:48

标签: c# wpf xaml datagrid

我正在尝试使用MVVMLight将DataTable绑定到DataGrid。我能够显示数据,但是当我尝试滚动网格或编辑单元格时,会出现许多绑定错误。这似乎导致性能问题,但我也很好奇他们出现的原因。在下面的代码中,我只填充了一个单元格,编辑新单元格时出现错误。其他时候我试过这个,我创建了更大的DataTables,当我滚动DataGrid时发生了同样的错误。我试过玩DataGrid的属性,但似乎没有什么可以摆脱错误。

编辑:我也尝试使用DefaultView,但似乎无法解决问题。

这是我的VM代码:

using GalaSoft.MvvmLight;
using System.Collections.ObjectModel;
using System.Data;
using System.Windows.Controls;
using System.Windows.Data;

namespace DatagridTest1.ViewModel
{
    public class MainViewModel : ViewModelBase
    {
    public DataTable Data2
        {
            get
            {
                return data2;
            }
            set
            {
                Set(() => Data2, ref data2, value);
            }
        }

        public MainViewModel()
        {
            Data2 = new DataTable();

            DataColumn testCol = new DataColumn("Test1");
            Data2.Columns.Add(testCol);
            DataRow testRow = Data2.NewRow();
            testRow[0] = "0";
            Data2.Rows.Add(testRow);
            Data2.AcceptChanges();
        }
    }
}

这是我的XAML:

<Window x:Class="DatagridTest1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:DatagridTest1"
        xmlns:diagnostics="clr-namespace:System.Diagnostics;assembly=WindowsBase"
        mc:Ignorable="d"
        Title="MainWindow" Height="350" Width="525">
    <Grid Focusable="False">
        <Grid.Resources>
            <local:Debug x:Key="Debugger"/>
        </Grid.Resources>
<DataGrid VirtualizingPanel.IsVirtualizing="False" HeadersVisibility="None" AutoGenerateColumns="True" ItemsSource="{Binding Data2, diagnostics:PresentationTraceSources.TraceLevel=High, Mode=TwoWay, Converter={StaticResource Debugger}}" DataContext="{Binding Main, Source={StaticResource Locator}}">
        </DataGrid>
    </Grid>
</Window>

以下是我得到的错误:

'DatagridTest1.vshost.exe' (CLR v4.0.30319: DatagridTest1.vshost.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_32\mscorlib\v4.0_4.0.0.0__b77a5c561934e089\mscorlib.dll'. Cannot find or open the PDB file.
'DatagridTest1.vshost.exe' (CLR v4.0.30319: DatagridTest1.vshost.exe): Loaded 'C:\WINDOWS\assembly\GAC_MSIL\Microsoft.VisualStudio.HostingProcess.Utilities\14.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.HostingProcess.Utilities.dll'. Cannot find or open the PDB file.
'DatagridTest1.vshost.exe' (CLR v4.0.30319: DatagridTest1.vshost.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Windows.Forms\v4.0_4.0.0.0__b77a5c561934e089\System.Windows.Forms.dll'. Cannot find or open the PDB file.
'DatagridTest1.vshost.exe' (CLR v4.0.30319: DatagridTest1.vshost.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System\v4.0_4.0.0.0__b77a5c561934e089\System.dll'. Cannot find or open the PDB file.
'DatagridTest1.vshost.exe' (CLR v4.0.30319: DatagridTest1.vshost.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Drawing\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Drawing.dll'. Cannot find or open the PDB file.
'DatagridTest1.vshost.exe' (CLR v4.0.30319: DatagridTest1.vshost.exe): Loaded 'C:\WINDOWS\assembly\GAC_MSIL\Microsoft.VisualStudio.HostingProcess.Utilities.Sync\14.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.HostingProcess.Utilities.Sync.dll'. Cannot find or open the PDB file.
'DatagridTest1.vshost.exe' (CLR v4.0.30319: DatagridTest1.vshost.exe): Loaded 'C:\WINDOWS\assembly\GAC_MSIL\Microsoft.VisualStudio.Debugger.Runtime\14.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.Debugger.Runtime.dll'. 
'DatagridTest1.vshost.exe' (CLR v4.0.30319: DatagridTest1.vshost.exe): Loaded 'C:\Users\William\Documents\Visual Studio 2015\Projects\DatagridTest1\DatagridTest1\bin\Debug\DatagridTest1.vshost.exe'. Cannot find or open the PDB file.
'DatagridTest1.vshost.exe' (CLR v4.0.30319: DatagridTest1.vshost.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_32\System.Data\v4.0_4.0.0.0__b77a5c561934e089\System.Data.dll'. Cannot find or open the PDB file.
'DatagridTest1.vshost.exe' (CLR v4.0.30319: DatagridTest1.vshost.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Core\v4.0_4.0.0.0__b77a5c561934e089\System.Core.dll'. Cannot find or open the PDB file.
'DatagridTest1.vshost.exe' (CLR v4.0.30319: DatagridTest1.vshost.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Xml\v4.0_4.0.0.0__b77a5c561934e089\System.Xml.dll'. Cannot find or open the PDB file.
'DatagridTest1.vshost.exe' (CLR v4.0.30319: DatagridTest1.vshost.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\Microsoft.CSharp\v4.0_4.0.0.0__b03f5f7f11d50a3a\Microsoft.CSharp.dll'. Cannot find or open the PDB file.
'DatagridTest1.vshost.exe' (CLR v4.0.30319: DatagridTest1.vshost.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Xml.Linq\v4.0_4.0.0.0__b77a5c561934e089\System.Xml.Linq.dll'. Cannot find or open the PDB file.
'DatagridTest1.vshost.exe' (CLR v4.0.30319: DatagridTest1.vshost.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Data.DataSetExtensions\v4.0_4.0.0.0__b77a5c561934e089\System.Data.DataSetExtensions.dll'. Cannot find or open the PDB file.
'DatagridTest1.vshost.exe' (CLR v4.0.30319: DatagridTest1.vshost.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Net.Http\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Net.Http.dll'. Cannot find or open the PDB file.
'DatagridTest1.vshost.exe' (CLR v4.0.30319: DatagridTest1.vshost.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Xaml\v4.0_4.0.0.0__b77a5c561934e089\System.Xaml.dll'. Cannot find or open the PDB file.
'DatagridTest1.vshost.exe' (CLR v4.0.30319: DatagridTest1.vshost.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\WindowsBase\v4.0_4.0.0.0__31bf3856ad364e35\WindowsBase.dll'. Cannot find or open the PDB file.
'DatagridTest1.vshost.exe' (CLR v4.0.30319: DatagridTest1.vshost.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_32\PresentationCore\v4.0_4.0.0.0__31bf3856ad364e35\PresentationCore.dll'. Cannot find or open the PDB file.
'DatagridTest1.vshost.exe' (CLR v4.0.30319: DatagridTest1.vshost.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\PresentationFramework\v4.0_4.0.0.0__31bf3856ad364e35\PresentationFramework.dll'. Cannot find or open the PDB file.
The thread 0x18e8 has exited with code 0 (0x0).
The thread 0x1e30 has exited with code 0 (0x0).
'DatagridTest1.vshost.exe' (CLR v4.0.30319: DatagridTest1.vshost.exe): Loaded 'C:\Users\William\Documents\Visual Studio 2015\Projects\DatagridTest1\DatagridTest1\bin\Debug\DatagridTest1.exe'. Symbols loaded.
'DatagridTest1.vshost.exe' (CLR v4.0.30319: DatagridTest1.vshost.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Configuration\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll'. Cannot find or open the PDB file.
'DatagridTest1.vshost.exe' (CLR v4.0.30319: DatagridTest1.vshost.exe): Loaded 'C:\Users\William\Documents\Visual Studio 2015\Projects\DatagridTest1\DatagridTest1\bin\Debug\Microsoft.Practices.ServiceLocation.dll'. Symbols loaded.
'DatagridTest1.vshost.exe' (CLR v4.0.30319: DatagridTest1.vshost.exe): Loaded 'C:\Users\William\Documents\Visual Studio 2015\Projects\DatagridTest1\DatagridTest1\bin\Debug\GalaSoft.MvvmLight.Extras.dll'. Symbols loaded.
'DatagridTest1.vshost.exe' (CLR v4.0.30319: DatagridTest1.vshost.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Runtime\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Runtime.dll'. Cannot find or open the PDB file.
'DatagridTest1.vshost.exe' (CLR v4.0.30319: DatagridTest1.vshost.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.ComponentModel\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.ComponentModel.dll'. Module was built without symbols.
'DatagridTest1.vshost.exe' (CLR v4.0.30319: DatagridTest1.vshost.exe): Loaded 'C:\Users\William\Documents\Visual Studio 2015\Projects\DatagridTest1\DatagridTest1\bin\Debug\GalaSoft.MvvmLight.dll'. Symbols loaded.
'DatagridTest1.vshost.exe' (CLR v4.0.30319: DatagridTest1.vshost.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.ObjectModel\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.ObjectModel.dll'. Module was built without symbols.
'DatagridTest1.vshost.exe' (CLR v4.0.30319: DatagridTest1.vshost.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Collections\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Collections.dll'. Cannot find or open the PDB file.
'DatagridTest1.vshost.exe' (CLR v4.0.30319: DatagridTest1.vshost.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Reflection\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Reflection.dll'. Cannot find or open the PDB file.
'DatagridTest1.vshost.exe' (CLR v4.0.30319: DatagridTest1.vshost.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Threading\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Threading.dll'. Cannot find or open the PDB file.
'DatagridTest1.vshost.exe' (CLR v4.0.30319: DatagridTest1.vshost.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Globalization\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Globalization.dll'. Cannot find or open the PDB file.
'DatagridTest1.vshost.exe' (CLR v4.0.30319: DatagridTest1.vshost.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Linq\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Linq.dll'. Cannot find or open the PDB file.
'DatagridTest1.vshost.exe' (CLR v4.0.30319: DatagridTest1.vshost.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Linq.Expressions\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Linq.Expressions.dll'. Module was built without symbols.
'DatagridTest1.vshost.exe' (CLR v4.0.30319: DatagridTest1.vshost.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Numerics\v4.0_4.0.0.0__b77a5c561934e089\System.Numerics.dll'. Cannot find or open the PDB file.
'DatagridTest1.vshost.exe' (CLR v4.0.30319: DatagridTest1.vshost.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\PresentationFramework.Aero2\v4.0_4.0.0.0__31bf3856ad364e35\PresentationFramework.Aero2.dll'. Cannot find or open the PDB file.
System.Windows.Data Warning: 56 : Created BindingExpression (hash=64505930) for Binding (hash=49162568)
System.Windows.Data Warning: 58 :   Path: 'Data2'
System.Windows.Data Warning: 61 : BindingExpression (hash=64505930): Default update trigger resolved to PropertyChanged
System.Windows.Data Warning: 62 : BindingExpression (hash=64505930): Attach to System.Windows.Controls.DataGrid.ItemsSource (hash=59593954)
System.Windows.Data Warning: 67 : BindingExpression (hash=64505930): Resolving source 
System.Windows.Data Warning: 70 : BindingExpression (hash=64505930): Found data context element: DataGrid (hash=59593954) (OK)
System.Windows.Data Warning: 71 : BindingExpression (hash=64505930): DataContext is null
System.Windows.Data Warning: 65 : BindingExpression (hash=64505930): Resolve source deferred
System.Windows.Data Information: 10 : Cannot retrieve value using the binding and no valid fallback value exists; using default instead. BindingExpression:Path=Data2; DataItem=null; target element is 'DataGrid' (Name=''); target property is 'ItemsSource' (type 'IEnumerable')
System.Windows.Data Information: 10 : Cannot retrieve value using the binding and no valid fallback value exists; using default instead. BindingExpression:Path=CellsPanelHorizontalOffset; DataItem=null; target element is 'Button' (Name=''); target property is 'Width' (type 'Double')
System.Windows.Data Information: 10 : Cannot retrieve value using the binding and no valid fallback value exists; using default instead. BindingExpression:Path=HeadersVisibility; DataItem=null; target element is 'Button' (Name=''); target property is 'Visibility' (type 'Visibility')
System.Windows.Data Information: 10 : Cannot retrieve value using the binding and no valid fallback value exists; using default instead. BindingExpression:Path=HeadersVisibility; DataItem=null; target element is 'DataGridColumnHeadersPresenter' (Name=''); target property is 'Visibility' (type 'Visibility')
System.Windows.Data Information: 10 : Cannot retrieve value using the binding and no valid fallback value exists; using default instead. BindingExpression:Path=NonFrozenColumnsViewportHorizontalOffset; DataItem=null; target element is 'ColumnDefinition' (HashCode=15863087); target property is 'Width' (type 'GridLength')
'DatagridTest1.vshost.exe' (CLR v4.0.30319: DatagridTest1.vshost.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\PresentationFramework-SystemXml\v4.0_4.0.0.0__b77a5c561934e089\PresentationFramework-SystemXml.dll'. Cannot find or open the PDB file.
System.Windows.Data Warning: 67 : BindingExpression (hash=64505930): Resolving source 
System.Windows.Data Warning: 70 : BindingExpression (hash=64505930): Found data context element: DataGrid (hash=59593954) (OK)
System.Windows.Data Warning: 78 : BindingExpression (hash=64505930): Activate with root item MainViewModel (hash=66305805)
System.Windows.Data Warning: 108 : BindingExpression (hash=64505930):   At level 0 - for MainViewModel.Data2 found accessor RuntimePropertyInfo(Data2)
System.Windows.Data Warning: 104 : BindingExpression (hash=64505930): Replace item at level 0 with MainViewModel (hash=66305805), using accessor RuntimePropertyInfo(Data2)
System.Windows.Data Warning: 101 : BindingExpression (hash=64505930): GetValue at level 0 from MainViewModel (hash=66305805) using RuntimePropertyInfo(Data2): DataTable (hash=35951058)
System.Windows.Data Warning: 80 : BindingExpression (hash=64505930): TransferValue - got raw value DataTable (hash=35951058)
System.Windows.Data Warning: 82 : BindingExpression (hash=64505930): TransferValue - user's converter produced DataTable (hash=35951058)
System.Windows.Data Warning: 84 : BindingExpression (hash=64505930): TransferValue - implicit converter produced DataView (hash=35751240 Count=1)
System.Windows.Data Warning: 89 : BindingExpression (hash=64505930): TransferValue - using final value DataView (hash=35751240 Count=1)
'DatagridTest1.vshost.exe' (CLR v4.0.30319: DatagridTest1.vshost.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\PresentationFramework-SystemData\v4.0_4.0.0.0__b77a5c561934e089\PresentationFramework-SystemData.dll'. Cannot find or open the PDB file.
System.Windows.Data Information: 10 : Cannot retrieve value using the binding and no valid fallback value exists; using default instead. BindingExpression:Path=AreRowDetailsFrozen; DataItem=null; target element is 'DataGridDetailsPresenter' (Name=''); target property is 'SelectiveScrollingOrientation' (type 'SelectiveScrollingOrientation')
System.Windows.Data Information: 10 : Cannot retrieve value using the binding and no valid fallback value exists; using default instead. BindingExpression:Path=HeadersVisibility; DataItem=null; target element is 'DataGridRowHeader' (Name=''); target property is 'Visibility' (type 'Visibility')
'DatagridTest1.vshost.exe' (CLR v4.0.30319: DatagridTest1.vshost.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Resources.ResourceManager\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Resources.ResourceManager.dll'. Cannot find or open the PDB file.
System.Windows.Data Information: 10 : Cannot retrieve value using the binding and no valid fallback value exists; using default instead. BindingExpression:Path=Test1; DataItem=null; target element is 'TextBlock' (Name=''); target property is 'Text' (type 'String')
System.Windows.Data Information: 10 : Cannot retrieve value using the binding and no valid fallback value exists; using default instead. BindingExpression:Path=ValidationErrorTemplate; DataItem=null; target element is 'Control' (Name=''); target property is 'Template' (type 'ControlTemplate')
System.Windows.Data Information: 10 : Cannot retrieve value using the binding and no valid fallback value exists; using default instead. BindingExpression:Path=(0); DataItem=null; target element is 'Control' (Name=''); target property is 'Visibility' (type 'Visibility')
System.Windows.Data Information: 10 : Cannot retrieve value using the binding and no valid fallback value exists; using default instead. BindingExpression:Path=NewItemMargin; DataItem=null; target element is 'DataGridRow' (Name=''); target property is 'Margin' (type 'Thickness')
System.Windows.Data Information: 10 : Cannot retrieve value using the binding and no valid fallback value exists; using default instead. BindingExpression:Path=AreRowDetailsFrozen; DataItem=null; target element is 'DataGridDetailsPresenter' (Name=''); target property is 'SelectiveScrollingOrientation' (type 'SelectiveScrollingOrientation')
System.Windows.Data Information: 10 : Cannot retrieve value using the binding and no valid fallback value exists; using default instead. BindingExpression:Path=HeadersVisibility; DataItem=null; target element is 'DataGridRowHeader' (Name=''); target property is 'Visibility' (type 'Visibility')
System.Windows.Data Information: 10 : Cannot retrieve value using the binding and no valid fallback value exists; using default instead. BindingExpression:Path=Test1; DataItem=null; target element is 'TextBlock' (Name=''); target property is 'Text' (type 'String')
System.Windows.Data Information: 10 : Cannot retrieve value using the binding and no valid fallback value exists; using default instead. BindingExpression:Path=ValidationErrorTemplate; DataItem=null; target element is 'Control' (Name=''); target property is 'Template' (type 'ControlTemplate')
System.Windows.Data Information: 10 : Cannot retrieve value using the binding and no valid fallback value exists; using default instead. BindingExpression:Path=(0); DataItem=null; target element is 'Control' (Name=''); target property is 'Visibility' (type 'Visibility')
'DatagridTest1.vshost.exe' (CLR v4.0.30319: DatagridTest1.vshost.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\PresentationFramework-SystemXmlLinq\v4.0_4.0.0.0__b77a5c561934e089\PresentationFramework-SystemXmlLinq.dll'. Cannot find or open the PDB file.
'DatagridTest1.vshost.exe' (CLR v4.0.30319: DatagridTest1.vshost.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\PresentationFramework-SystemCore\v4.0_4.0.0.0__b77a5c561934e089\PresentationFramework-SystemCore.dll'. Cannot find or open the PDB file.
System.Windows.Data Information: 42 : BindingExpression path error: 'Test1' property not found for 'object' because data item is the NewItemPlaceholder. BindingExpression:Path=Test1; DataItem='NamedObject' (HashCode=50804710); target element is 'TextBlock' (Name=''); target property is 'Text' (type 'String')
System.Windows.Data Information: 20 : BindingExpression cannot retrieve value due to missing information. BindingExpression:Path=Test1; DataItem='NamedObject' (HashCode=50804710); target element is 'TextBlock' (Name=''); target property is 'Text' (type 'String')
System.Windows.Data Information: 21 : BindingExpression cannot retrieve value from null data item. This could happen when binding is detached or when binding to a Nullable type that has no value. BindingExpression:Path=Test1; DataItem='NamedObject' (HashCode=50804710); target element is 'TextBlock' (Name=''); target property is 'Text' (type 'String')
System.Windows.Data Information: 10 : Cannot retrieve value using the binding and no valid fallback value exists; using default instead. BindingExpression:Path=Test1; DataItem='NamedObject' (HashCode=50804710); target element is 'TextBlock' (Name=''); target property is 'Text' (type 'String')
'DatagridTest1.vshost.exe' (CLR v4.0.30319: DatagridTest1.vshost.exe): Loaded 'C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO 14.0\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\CLIENTDIAGNOSTICS\XAMLDIAGNOSTICS\x86\WpfXamlDiagnosticsTap.dll'. Cannot find or open the PDB file.
'DatagridTest1.vshost.exe' (CLR v4.0.30319: DatagridTest1.vshost.exe): Loaded 'C:\WINDOWS\assembly\GAC\Microsoft.VisualStudio.OLE.Interop\7.1.40304.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.OLE.Interop.dll'. Module was built without symbols.
'DatagridTest1.vshost.exe' (CLR v4.0.30319: DatagridTest1.vshost.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\UIAutomationTypes\v4.0_4.0.0.0__31bf3856ad364e35\UIAutomationTypes.dll'. Cannot find or open the PDB file.
System.Windows.Data Information: 10 : Cannot retrieve value using the binding and no valid fallback value exists; using default instead. BindingExpression:Path=NewItemMargin; DataItem=null; target element is 'DataGridRow' (Name=''); target property is 'Margin' (type 'Thickness')
System.Windows.Data Information: 10 : Cannot retrieve value using the binding and no valid fallback value exists; using default instead. BindingExpression:Path=AreRowDetailsFrozen; DataItem=null; target element is 'DataGridDetailsPresenter' (Name=''); target property is 'SelectiveScrollingOrientation' (type 'SelectiveScrollingOrientation')
System.Windows.Data Information: 10 : Cannot retrieve value using the binding and no valid fallback value exists; using default instead. BindingExpression:Path=HeadersVisibility; DataItem=null; target element is 'DataGridRowHeader' (Name=''); target property is 'Visibility' (type 'Visibility')
System.Windows.Data Information: 10 : Cannot retrieve value using the binding and no valid fallback value exists; using default instead. BindingExpression:Path=Test1; DataItem=null; target element is 'TextBlock' (Name=''); target property is 'Text' (type 'String')
System.Windows.Data Information: 10 : Cannot retrieve value using the binding and no valid fallback value exists; using default instead. BindingExpression:Path=ValidationErrorTemplate; DataItem=null; target element is 'Control' (Name=''); target property is 'Template' (type 'ControlTemplate')
System.Windows.Data Information: 10 : Cannot retrieve value using the binding and no valid fallback value exists; using default instead. BindingExpression:Path=(0); DataItem=null; target element is 'Control' (Name=''); target property is 'Visibility' (type 'Visibility')
System.Windows.Data Information: 10 : Cannot retrieve value using the binding and no valid fallback value exists; using default instead. BindingExpression:Path=Test1; DataItem='DataRowView' (HashCode=55668938); target element is 'TextBlock' (Name=''); target property is 'Text' (type 'String')
System.Windows.Data Information: 10 : Cannot retrieve value using the binding and no valid fallback value exists; using default instead. BindingExpression:Path=Test1; DataItem=null; target element is 'TextBox' (Name=''); target property is 'Text' (type 'String')
System.Windows.Data Information: 41 : BindingExpression path error: 'Test1' property not found for 'object' because data item is null.  This could happen because the data provider has not produced any data yet. BindingExpression:Path=Test1; DataItem=null; target element is 'TextBlock' (Name=''); target property is 'Text' (type 'String')
System.Windows.Data Information: 20 : BindingExpression cannot retrieve value due to missing information. BindingExpression:Path=Test1; DataItem=null; target element is 'TextBlock' (Name=''); target property is 'Text' (type 'String')
System.Windows.Data Information: 21 : BindingExpression cannot retrieve value from null data item. This could happen when binding is detached or when binding to a Nullable type that has no value. BindingExpression:Path=Test1; DataItem=null; target element is 'TextBlock' (Name=''); target property is 'Text' (type 'String')
System.Windows.Data Information: 10 : Cannot retrieve value using the binding and no valid fallback value exists; using default instead. BindingExpression:Path=Test1; DataItem=null; target element is 'TextBlock' (Name=''); target property is 'Text' (type 'String')
System.Windows.Data Information: 10 : Cannot retrieve value using the binding and no valid fallback value exists; using default instead. BindingExpression:Path=Test1; DataItem='DataRowView' (HashCode=55668938); target element is 'TextBox' (Name=''); target property is 'Text' (type 'String')
System.Windows.Data Information: 10 : Cannot retrieve value using the binding and no valid fallback value exists; using default instead. BindingExpression:Path=Test1; DataItem='DataRowView' (HashCode=55668938); target element is 'DataGridCell' (Name=''); target property is 'CellContent' (type 'String')
System.Windows.Data Information: 10 : Cannot retrieve value using the binding and no valid fallback value exists; using default instead. BindingExpression:Path=Test1; DataItem=null; target element is 'TextBlock' (Name=''); target property is 'Text' (type 'String')
System.Windows.Data Information: 41 : BindingExpression path error: 'Test1' property not found for 'object' because data item is null.  This could happen because the data provider has not produced any data yet. BindingExpression:Path=Test1; DataItem=null; target element is 'TextBox' (Name=''); target property is 'Text' (type 'String')
System.Windows.Data Information: 20 : BindingExpression cannot retrieve value due to missing information. BindingExpression:Path=Test1; DataItem=null; target element is 'TextBox' (Name=''); target property is 'Text' (type 'String')
System.Windows.Data Information: 21 : BindingExpression cannot retrieve value from null data item. This could happen when binding is detached or when binding to a Nullable type that has no value. BindingExpression:Path=Test1; DataItem=null; target element is 'TextBox' (Name=''); target property is 'Text' (type 'String')
System.Windows.Data Information: 10 : Cannot retrieve value using the binding and no valid fallback value exists; using default instead. BindingExpression:Path=Test1; DataItem=null; target element is 'TextBox' (Name=''); target property is 'Text' (type 'String')
System.Windows.Data Information: 10 : Cannot retrieve value using the binding and no valid fallback value exists; using default instead. BindingExpression:Path=Test1; DataItem='DataRowView' (HashCode=55668938); target element is 'DataGridRow' (Name=''); target property is 'NoTarget' (type 'Object')

感谢您的帮助!

1 个答案:

答案 0 :(得分:0)

您不应在WPF中使用System.Data命名空间类。使用正确的INotifyProperyChanged实现创建自己的模型,并使用ObservableCollection作为列表。

但是,如果您仍想使用DataTable,请参阅this post。 (看起来像DataTable.DefaultView属性是一个键)