473,396 Members | 1,942 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

XAML ObjectDataProvider, ObjectType Error

I'm a trying to instantiate an object (that was created in C#) in XAML using the ObjectDataProvider. Unfortunately, I'm receiving the following error: "The type reference cannot find a public type named 'TYPENAME'". I have a .cs file of the same name as the the TYPENAME.

Here's my XAML:
Expand|Select|Wrap|Line Numbers
  1. <Window x:Class="PROJECTNAME.PROJECTFILE"
  2.         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  3.         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  4.         xmlns:dg="http://schemas.microsoft.com/wpf/2008/toolkit"
  5.         xmlns:local="clr-namespace:PROJECTNAME"
  6.         Title="PROJECTFILE" Height="500" Width="500">
  7.     <Window.Resources>
  8.         <ResourceDictionary>
  9.             <ObjectDataProvider x:Key="NAME1" ObjectType="{x:Type TYPENAME}"/>
  10.             <ObjectDataProvider x:Key="NAME2" ObjectInstance="{StaticResource TYPENAME}" MethodName="METHODNAME"/>
  11.         </ResourceDictionary>
  12.     </Window.Resources>
  13.     <Grid Height="375">
  14.         <DockPanel DataContext="{Binding Source={StaticResource TYPENAME}}" Width="440" Margin="10,20,191,35">
  15.             <dg:DataGrid Name="DG" ItemsSource="{Binding}"/>
  16.         </DockPanel>
  17.         <DockPanel Width="85" Height="25" Margin="0,350,0,0">
  18.             <Frame Name="Frame"/>
  19.             <Button Content="See Posts Info" Click="Button_Click"/>
  20.         </DockPanel>
  21.     </Grid>
  22. </Window>
  23.  
Here's the C# file for TYPENAME:
Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Data;
  6.  
  7. namespace PROJECTNAME
  8. {
  9.     class TYPENAME
  10.     {
  11.         private AccesDBDataSet data_set;
  12.         private AccesDBDataSetTableAdapters.tblTYPENAMETableAdapter TYPENAMEAdapter;
  13.  
  14.         public TYPENAME()
  15.         {
  16.             data_set = new AccesDBDataSet();
  17.             DataTable tblTYPENAME = data_set.Tables[1];
  18.             TYPENAMEAdapter = new AccesDBDataSetTableAdapters.TYPENAMEAdapterTableAdapter();
  19.             TYPENAMEAdapter.Fill(data_set.tblTYPENAMEAdapter);
  20.         }
  21.  
  22.         public DataView METHODNAME()
  23.         {
  24.             return data_set.tblTYPENAMEAdapter.DefaultView;
  25.         }
  26.     }
  27. }
  28.  
So, why exactly is TYPENAME unrecognized in line 9 of the XAML? Am I formatting it incorrectly? I tried setting it up as
Expand|Select|Wrap|Line Numbers
  1. <ObjectDataProvider x:Key="NAME1" ObjectType="{x:Type local:TYPENAME}"/>
but that caused the same bug.

Thanks for the help!
Aug 23 '13 #1

✓ answered by Frinavale

I'm not sure what you are doing wrong because I cannot reproduce it.

I added a window to my project called ProjectFile (same as yours except not in all caps).

I then added a class called TypeName and used the normal DataSet instead of the access one since I don't have that available.

Lastly, I copied and pasted your XAML markup and made some binding adjustments to get it to work properly (as per the corrections I suggested before).

I am unable to reproduce the problem that you are having.

This is my XAML
Expand|Select|Wrap|Line Numbers
  1. <Window x:Class="ProjectFile"
  2.         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  3.         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  4.         xmlns:local="clr-namespace:ProjectName"
  5.         Title="ProjectFile" Height="300" Width="300">
  6.     <Window.Resources>
  7.         <ResourceDictionary>
  8.             <ObjectDataProvider x:Key="NAME1" ObjectType="{x:Type local:TypeName}"/>
  9.             <ObjectDataProvider x:Key="NAME2" ObjectInstance="{StaticResource NAME1}" MethodName="MethodName"/>
  10.         </ResourceDictionary>
  11.     </Window.Resources>
  12.     <Grid Height="375">
  13.         <DockPanel DataContext="{Binding Source={StaticResource NAME2}}" Width="440" Margin="10,20,191,35">
  14.             <DataGrid Name="DG" ItemsSource="{Binding}"/>
  15.         </DockPanel>
  16.         <DockPanel Width="85" Height="25" Margin="0,350,0,0">
  17.             <Frame Name="Frame"/>
  18.             <Button Content="See Posts Info" />
  19.         </DockPanel>
  20.     </Grid>
  21. </Window>
  22.  
This is my code for the TypeName class:

(VB)
Expand|Select|Wrap|Line Numbers
  1. Class TypeName
  2.     Private data_set As System.Data.DataSet
  3.     Public Sub New()
  4.         data_set = New System.Data.DataSet()
  5.         Dim tblTypeName As New System.Data.DataTable
  6.         tblTypeName.Columns.Add("Col1")
  7.         tblTypeName.Columns.Add("Col2")
  8.         For i As Integer = 0 To 10
  9.             Dim dr As System.Data.DataRow = tblTypeName.NewRow
  10.             dr(0) = String.Format("{0} ", i.ToString)
  11.             dr(1) = String.Format("{0} ", i.ToString)
  12.             tblTypeName.Rows.Add(dr)
  13.         Next
  14.         data_set.Tables.Add(tblTypeName)
  15.     End Sub
  16.  
  17.     Public Function MethodName() As System.Data.DataView
  18.         Return data_set.Tables(0).DefaultView
  19.     End Function
  20. End Class
(C#)
Expand|Select|Wrap|Line Numbers
  1. class TypeName
  2. {
  3.     private System.Data.DataSet data_set;
  4.     public TypeName()
  5.     {
  6.         data_set = new System.Data.DataSet();
  7.         System.Data.DataTable tblTypeName = new System.Data.DataTable();
  8.         tblTypeName.Columns.Add("Col1");
  9.         tblTypeName.Columns.Add("Col2");
  10.         for (int i = 0; i <= 10; i++) {
  11.             System.Data.DataRow dr = tblTypeName.NewRow();
  12.             dr[0] = string.Format("{0} ", i.ToString());
  13.             dr[1] = string.Format("{0} ", i.ToString());
  14.             tblTypeName.Rows.Add(dr);
  15.         }
  16.         data_set.Tables.Add(tblTypeName);
  17.     }
  18.  
  19.     public System.Data.DataView MethodName()
  20.     {
  21.         return data_set.Tables[0].DefaultView;
  22.     }
  23. }
The only thing that I can think that is going wrong is that something didn't compile properly and so you are getting a strange error.

-Frinny

3 7325
Frinavale
9,735 Expert Mod 8TB
I'm not sure why you are seeing the error but I noticed that your source is incorrect for your DockPanel in your XAML. You are attempting to bind to a Static Resource called TYPENAME but the key for that resource is actually NAME2.

Try fixing your binding and see if it fixes the problem.
If it doesn't I'll try and reproduce the problem here.

-Frinny
Aug 27 '13 #2
That actually didn't fix it.

Thanks, though; you saved me an error later one, I'm sure.
Aug 27 '13 #3
Frinavale
9,735 Expert Mod 8TB
I'm not sure what you are doing wrong because I cannot reproduce it.

I added a window to my project called ProjectFile (same as yours except not in all caps).

I then added a class called TypeName and used the normal DataSet instead of the access one since I don't have that available.

Lastly, I copied and pasted your XAML markup and made some binding adjustments to get it to work properly (as per the corrections I suggested before).

I am unable to reproduce the problem that you are having.

This is my XAML
Expand|Select|Wrap|Line Numbers
  1. <Window x:Class="ProjectFile"
  2.         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  3.         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  4.         xmlns:local="clr-namespace:ProjectName"
  5.         Title="ProjectFile" Height="300" Width="300">
  6.     <Window.Resources>
  7.         <ResourceDictionary>
  8.             <ObjectDataProvider x:Key="NAME1" ObjectType="{x:Type local:TypeName}"/>
  9.             <ObjectDataProvider x:Key="NAME2" ObjectInstance="{StaticResource NAME1}" MethodName="MethodName"/>
  10.         </ResourceDictionary>
  11.     </Window.Resources>
  12.     <Grid Height="375">
  13.         <DockPanel DataContext="{Binding Source={StaticResource NAME2}}" Width="440" Margin="10,20,191,35">
  14.             <DataGrid Name="DG" ItemsSource="{Binding}"/>
  15.         </DockPanel>
  16.         <DockPanel Width="85" Height="25" Margin="0,350,0,0">
  17.             <Frame Name="Frame"/>
  18.             <Button Content="See Posts Info" />
  19.         </DockPanel>
  20.     </Grid>
  21. </Window>
  22.  
This is my code for the TypeName class:

(VB)
Expand|Select|Wrap|Line Numbers
  1. Class TypeName
  2.     Private data_set As System.Data.DataSet
  3.     Public Sub New()
  4.         data_set = New System.Data.DataSet()
  5.         Dim tblTypeName As New System.Data.DataTable
  6.         tblTypeName.Columns.Add("Col1")
  7.         tblTypeName.Columns.Add("Col2")
  8.         For i As Integer = 0 To 10
  9.             Dim dr As System.Data.DataRow = tblTypeName.NewRow
  10.             dr(0) = String.Format("{0} ", i.ToString)
  11.             dr(1) = String.Format("{0} ", i.ToString)
  12.             tblTypeName.Rows.Add(dr)
  13.         Next
  14.         data_set.Tables.Add(tblTypeName)
  15.     End Sub
  16.  
  17.     Public Function MethodName() As System.Data.DataView
  18.         Return data_set.Tables(0).DefaultView
  19.     End Function
  20. End Class
(C#)
Expand|Select|Wrap|Line Numbers
  1. class TypeName
  2. {
  3.     private System.Data.DataSet data_set;
  4.     public TypeName()
  5.     {
  6.         data_set = new System.Data.DataSet();
  7.         System.Data.DataTable tblTypeName = new System.Data.DataTable();
  8.         tblTypeName.Columns.Add("Col1");
  9.         tblTypeName.Columns.Add("Col2");
  10.         for (int i = 0; i <= 10; i++) {
  11.             System.Data.DataRow dr = tblTypeName.NewRow();
  12.             dr[0] = string.Format("{0} ", i.ToString());
  13.             dr[1] = string.Format("{0} ", i.ToString());
  14.             tblTypeName.Rows.Add(dr);
  15.         }
  16.         data_set.Tables.Add(tblTypeName);
  17.     }
  18.  
  19.     public System.Data.DataView MethodName()
  20.     {
  21.         return data_set.Tables[0].DefaultView;
  22.     }
  23. }
The only thing that I can think that is going wrong is that something didn't compile properly and so you are getting a strange error.

-Frinny
Sep 4 '13 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Kenneth Baltrinic | last post by:
I am getting the following error when deserializing an object that has a couple of dozen dependant objects in its object graph. Anyone who can suggest where I might begin to look to resolve problem...
4
by: Thilaka | last post by:
Hi guys, Recently i read some articles on Longhorn & XAML. & From what i learnt the future for developing UIs lies in XAML. Does this mean that I've got to learn XAML as developing UIs for web...
1
by: jide | last post by:
Hi, I tried to add a wmp to XAML via WindowsFormsHost and when compiling, i got an error message telling that "Grid has an invalid child". I did use the namespaces etc. The same error occurs...
0
by: BRitchie | last post by:
I came across a small problem (and solution), if I have an ObjectDataProvider in my resources section and I need to have it loaded with the form all I could come up with is to use an ICommand...
4
by: Lloyd Dupont | last post by:
In my application I want to display some data in a list box. I need to display the data as a picture. My 1st idea was to create a ValueConverter to convert my datas to ImageSource But this has...
0
by: Oriane | last post by:
Bonjour, With Asp.Net futures (Microsoft.Web.Preview), I can't use the Media and Xaml controls (Silverlight). I've got this error messages, with several wmv files: Execution error: ...
1
by: eljainc | last post by:
Hello, I have a problem when working with a program that uses XAML in one of the modules. I copied some XAML code from another working project into an existing project, then when trying to...
0
by: Andy | last post by:
Hi, I have a ListBox on a Xaml Window, which is bound to an ObjectDataProvider with IsAsyncronous set to True. The window displays and the list box displays, initially empty. After a few...
1
by: moondaddy | last post by:
I need to use an ObjectDataProvider in a resource file to pull in the System.Window.TextAlignment enum which is part of the PresentationCore.DLL. I was able to do this with the...
1
jhardman
by: jhardman | last post by:
I'm working with my first real xbap project, and I have run into a real wall. Although my project runs just fine when debugging and I get no error while building, immediately as the publish finishes...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.