Hi all,
I am attempting data binding in WPF. I have a class Recipe and another called RecipeService. There seems a problem with the RecipeService class in terms of compatibility with the Recipe class as when I add its type to the ObjectDataProvider in the XAML file, I get an error that RecipeList type is not found. Any suggestions?
Furthermore, I am using Visual Studio.Net and the "Recipe" text in "public List<Recipe> GetRecipeList()" should be highlighted to Blue if accurate, however it is not.
Your suggestions are appreciated.
The code is below...
/*C# code*/
using System.Collections.Generic;
namespace TestApp
{
public class Recipe
{
private int _id;
private string _title; //can be used as recipe name
private string _mealType;
public Recipe(int id, string title, string _mealType)
{
_id = id;
_title = title;
_mealType = mealType;
}
public int Id
{
get { return _id; }
set { _id = value; }
}
public string Title
{
get { return _title; }
set { _title = value; }
}
public string MealType
{
get { return _mealType; }
set { _mealType = value; }
}
}
class RecipeService
{
public List<Recipe> GetRecipeList()
{
Recipe pasta = new Recipe(1, "Pasta", "Lunch");
Recipe toast = new Recipe(2, "Toast", "Breakfast");
List<Recipe> recipeList = new List<Recipe>();
recipeList.Add(pasta);
recipeList.Add(toast);
return recipeList;
}
}
}
<!--Some part of the code in the XAML File-->
<StackPanel>
<StackPanel.Resources>
<ObjectDataProvider x:Key="recipes" ObjectType="{x:Type svc:RecipeService}" MethodName="GetRecipeList" ></ObjectDataProvider>
</StackPanel.Resources>
</StackPanel>
<!--Here is the error message-->
error MC3050: Cannot find the type 'svc:RecipeService'. Note that type names are case sensitive.