2010-03-25 96 views
0

我已经使用张贴在奇妙例如:一个WPF数据网格绑定到数据表

http://www.codeproject.com/KB/WPF/WPFDataGridExamples.aspx

到WPF DataGrid绑定到一个数据表。

下面的源代码编译细;它甚至运行并在WPF数据网格中显示InfoWork数据表的内容。万岁!但带有datagrid的WPF页面不会显示在设计器中。我在我的设计页面上看到了一个难以理解的错误,而这个错误在本文末尾显示。我假设设计师在实例化数据视图以便在网格中显示时遇到了一些困难。我该如何解决这个问题?

XAML代码:

xmlns:local="clr-namespace:InfoSeeker" 

<Window.Resources> 
    <ObjectDataProvider 
     x:Key="InfoWorkData" 
     ObjectType="{x:Type local:InfoWorkData}" /> 
    <ObjectDataProvider 
     x:Key="InfoWork" 
     ObjectInstance="{StaticResource InfoWorkData}" 
     MethodName="GetInfoWork" /> 
</Window.Resources> 


<my:DataGrid 
    DataContext="{Binding Source={StaticResource InfoWork}}" 
    AutoGenerateColumns="True" 
    ItemsSource="{Binding}" 
    Name="dataGrid1" 
    xmlns:my="http://schemas.microsoft.com/wpf/2008/toolkit" /> 

C#代码:代替设计师页面的显示

namespace InfoSeeker 
{ 
    public class InfoWorkData 
    { 
     private InfoTableAdapters.InfoWorkTableAdapter infoAdapter; 
     private Info infoDS; 

     public InfoWorkData() 
     { 
      infoDS = new Info(); 
      infoAdapter = new InfoTableAdapters.InfoWorkTableAdapter(); 
      infoAdapter.Fill(infoDS.InfoWork); 
     } 
     public DataView GetInfoWork() 
     { 
      return infoDS.InfoWork.DefaultView; 
     } 
    } 
} 

错误上它具有电网:

发生未处理的异常:

类型“MS.Internal.Permission s.UserInitiatedNavigationPermission”在 大会 'PresentationFramework,版本= 3.0.0.0,文化=中立, 公钥= 31bf3856ad364e35' 未标记为可序列。在 System.Runtime.Serialization.FormatterServices.InternalGetSerializableMembers(RuntimeType 型)在 System.Runtime.Serialization.FormatterServices.GetSerializableMembers(类型 型,的StreamingContext上下文)在 System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitMemberInfo () 在 System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitSerialize(对象 OBJ,ISurrogateSelector surrogateSelector,的StreamingContext上下文, serObjectInfoInit serObjectInfoInit,IFormatterConverter来转换器, objectWriter objectWriter) ......在:Ms.Internal。 Designer.DesignerPane.LoadDesignerView()

编辑:修复我的Visual Studio。至少它给了我一个更好的错误消息:

请求类型的 “System.Data.OleDb.OleDBPermission,system.Data许可,版本= 2.0.0.0, 文化=中立,公钥= b77a5c561934e089 '失败。

回答

2

我开发的项目是(公司)网络驱动器上。如果我将项目移动到本地C:驱动器,错误消失。