【发布时间】:2015-11-19 11:18:37
【问题描述】:
我目前正在从硬编码的数据中填充我的 Windows 磁贴(我想确保我可以先让它工作......)。我所拥有的...它适用于硬编码信息。
我想要尝试做的是从我的 LINQ 查询中提取信息并将它们放入几个变量中,然后将这些变量放入 Tile。
我正在使用网络服务来联系我的 SQL 数据库,并将提供该服务以及我所拥有的以下信息:
网络服务
[OperationContract]
List<TBL_My_Info> FindInfo(string uid);
public List<TBL_My_Info> FindInfo(string uid)
{
DataClasses1DataContext context = new DataClasses1DataContext();
var res = from r in context.TBL_My_Info where r.User_Name == uid select r;
return res.ToList();
}
我可以验证查询是否提取了我需要的 3 条信息,即 Title、Description 和 Author。我遇到的麻烦是将这 3 个部分分配给它们各自的变量,以便我可以在我的磁贴中显示它们。
我的问题是我不确定如何使用我的LINQ 查询结果将它们分配给PrimaryTile..中的变量。
这是我硬编码磁贴的值以确保它正确显示的地方:
private void UpdatePrimaryTile(object sender, Windows.UI.Xaml.RoutedEventArgs e)
{
var xmlDoc = TileService.CreateTiles(new PrimaryTile());
var updater = TileUpdateManager.CreateTileUpdaterForApplication();
TileNotification notification = new TileNotification(xmlDoc);
updater.Update(notification);
}
public class PrimaryTile
{
public string time { get; set; } = "8:15 AM, Saturday";
public string message { get; set; } = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore.";
public string message2 { get; set; } = " At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident.";
public string branding { get; set; } = "name";
public string appName { get; set; } = "HoL";
}
public static Windows.Data.Xml.Dom.XmlDocument CreateTiles(PrimaryTile primaryTile)
{
XDocument xDoc = new XDocument(
new XElement("tile", new XAttribute("version", 3),
new XElement("visual",
// Small Tile
new XElement("binding", new XAttribute("branding",
primaryTile.branding), new XAttribute("displayName", primaryTile.appName), new XAttribute("template", "TileSmall"),
new XElement("group",
new XElement("subgroup",
new XElement("text", primaryTile.time, new XAttribute("hint-style", "caption")),
new XElement("text", primaryTile.message, new
XAttribute("hint-style", "captionsubtle"), new XAttribute("hint-wrap", true), new XAttribute("hint-maxLines", 3))
)
)
),
// Medium Tile
new XElement("binding", new XAttribute("branding", primaryTile.branding),
new XAttribute("displayName", primaryTile.appName), new XAttribute("template", "TileMedium"),
new XElement("group", new XElement("subgroup",
new XElement("text", primaryTile.time, new XAttribute("hint-style", "caption")),
new XElement("text", primaryTile.message, new XAttribute("hint-style", "captionsubtle"),
new XAttribute("hint-wrap", true), new XAttribute("hint-maxLines", 3))
)
)
)
)
)
);
Windows.Data.Xml.Dom.XmlDocument xmlDoc = new Windows.Data.Xml.Dom.XmlDocument();
xmlDoc.LoadXml(xDoc.ToString());
return xmlDoc;
}
【问题讨论】:
标签: c# xml linq win-universal-app