【发布时间】:2017-10-11 05:27:10
【问题描述】:
我正在尝试使用 Visual Studio 2017 在 Xamarin Froms 中制作一个非常简单的跨平台应用程序。该应用程序的目的是在小型 GridView 中显示食物食谱,带有食谱名称及其图片。
我使用以下静态类文件为食谱添加数据。 (RecipeData.cs)
**// Class that adds Data to Recipe Items**
public static class RecipeData
{
static List<Recipe> _allRecipes;
public static List<Recipe> AllRecipes
{
//List<Recipe> _allRecipes = new List<Recipe>();
get
{
if(_allRecipes == null)
{
_allRecipes = new List<Recipe>
{
new Recipie
{
RecipeName="Eggs Benedict",
CookTime = "24 min",
PreprationTime = "5 min",
NumberOfServing = 8,
WillMakeAgain = true,
MealType = MealType.Breakfast,
Difficulty = Difficulty.Easy,
Directions="1. Fill a large saucepan with about 4 inches of water, add vinegar, and bring to a boil. Fill a shallow dish or pie plate with warm water. Reduce heat under saucepan to medium, so water is just barely simmering. Break 1 egg at a time into a small heat-proof bowl. Gently tip bowl into water; carefully slide egg into water. Repeat with remaining eggs.\n\n2. When eggs begin to become opaque, remove them from the saucepan with a slotted spoon in the order in which they were added. Transfer the eggs to the dish of warm water. This process should take about 3 minutes.\n\n3. Prepare the hollandaise sauce, and set aside, keeping it warm.\n\n4. Heat a medium skillet over medium heat. Add Canadian bacon, and cook until well browned on both sides. Divide bacon among the English-muffin halves. For each serving, use a slotted spoon to remove one egg from warm water; set spoon and egg briefly on a clean cloth or paper towel to drain. Gently place the egg on a bacon-topped muffin, and spoon the reserved warm hollandaise sauce over the top.",
Ingredients="1 tablespoon white vinegar" + Environment.NewLine +
"8 large eggs\nHollandaise Sauce" + Environment.NewLine +
"1/2 pound (16 slices) Canadian bacon" + Environment.NewLine +
"4 English muffins, split in half, toasted",
ImageName = "Muffin.jpg"
},
这是我的项目文件的样子:
我当前项目文件的屏幕截图(显示我有 Muffin.jpg 图片)
要将字符串值转换为图像类型,我使用 ImageBindingConver 类
class ImageBindingConverter : IValueConverter
{
public string Assembly { get; set; }
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
var source = value as string;
if (string.IsNullOrEmpty(source))
return null;
var imagePath = $"{Assembly}.{source}";
return ImageSource.FromResource(imagePath);
}
这是配方类的 Xaml 文件 RecipiePage.xaml 这些是我用来显示 RecipePage 的所有页面,但图像没有显示,我也没有收到任何错误消息。如果有人可以提供帮助,我已经花费了很多时间。谢谢
【问题讨论】:
标签: c# xaml xamarin.forms visual-studio-2017