【发布时间】:2011-08-16 12:39:33
【问题描述】:
我正在尝试将 Videogame 对象的集合绑定到我的 ListBox,尽管遵循了 MSDN 示例,但我收到了此错误。
<Grid>
<Grid.Resources>
//Error is fired here.
<src:Videogames x:Key="videogames" />
这是我的电子游戏课:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.ObjectModel;
namespace UpcomingGames
{
public class Videogame
{
public string Name { get; set; }
public string ReleaseDate { get; set; }
public string Synopsis { get; set; }
public string Developer { get; set; }
}
public class Videogames : ObservableCollection<Videogame>
{
public Videogames()
{
Add(new Videogame {
Name = "Fire Emblem",
ReleaseDate = "20/4/2011",
Developer = "Rockstar Games",
Synopsis = @"Lorem ipsum dolor...",
});
Add(new Videogame {
Name = "Fire Emblem",
ReleaseDate = "20/4/2011",
Developer = "Rockstar Games",
Synopsis = @"Lorem ipsum dolor...",
});
Add(new Videogame{
Name = "Fire Emblem",
ReleaseDate = "20/4/2011",
Developer = "Rockstar Games",
Synopsis = @"Lorem ipsum dolor...",
});
}
}
}
我可能做错了什么,我能做些什么来解决这个问题?
我没有手动添加任何命名空间,因为 MSDN 文章没有告诉我。这是我需要做的吗?无论如何,这是 XAML 的当前状态。
<Window x:Class="UpcomingGames.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="286" Width="199">
【问题讨论】:
-
您可以将您的 xaml 代码粘贴到您添加命名空间 srv 的位置吗?
-
@RV1987:当然,请看我的编辑。
-
@RV1987:我也遇到了这个错误,我怀疑这是导致另一个主要错误的原因。
Error 2 ''src' is an undeclared prefix. Line 7, position 14.' XML is not valid. -
正如 Dave 已经提到的,您需要添加引用..
标签: wpf xaml binding listbox datatemplate