爲什麼這一工作是這樣的:爲什麼這段代碼不能工作? XML與.StartsWith
XDocument dataFeed = XDocument.Parse(e.Result);
var guide = from query in dataFeed.Descendants("MaxPayne3")
select new NewGamesClass
{
GameID = (string)query.Element("ID"),
GameTitle = (string)query.Element("Title"),
GameDescription = (string)query.Element("Description"),
GameGuide = (string)query.Element("Guide")
};
if (NavigationContext.QueryString.TryGetValue("selectedItem", out selectedIndex))
{
if (selectedIndex == "0")
GuidesListBox.ItemsSource = guide.Where(ngc => ngc.GameTitle.StartsWith("Feel"));
else if (selectedIndex == "1")
GuidesListBox.ItemsSource = guide.Where(ngc => ngc.GameTitle.StartsWith("Serious"));
但不喜歡這樣:
if (selectedIndex == "0")
GuidesListBox.ItemsSource = guide.Where(ngc => ngc.GameID.StartsWith("000"));
else if (selectedIndex == "1")
GuidesListBox.ItemsSource = guide.Where(ngc => ngc.GameID.StartsWith("001"));
我想用遊戲ID,而不是GameTitle。
抱歉沒有XML,早上我來說太早了,笑
這裏: https://dl.dropbox.com/u/27136243/AchivementHunters/XML/GameList.xml
這裏是類:
public class NewGamesClass
{
string gameID;
string gameTitle;
string gamedescription;
string gameImage;
string gameGuide;
string videoLink;
public string GameID
{ get { return gameID; } set { gameID = value; } }
public string GameTitle
{ get { return gameTitle; } set { gameTitle = value; } }
public string GameDescription
{ get { return gamedescription; } set { gamedescription = value; } }
public string GameImage
{ get { return gameImage; } set { gameImage = value; } }
public string GameGuide
{ get { return gameGuide; } set { gameGuide = value; } }
public string VideoLink
{ get { return videoLink; } set { videoLink = value; } }
}
是GameID的一個字符串? – 2012-07-18 10:29:21
-1:沒有XML提供 – 2012-07-18 10:29:29
你還沒有說過它不工作的方式。 – 2012-07-18 10:29:36