从 LINQ 查询(Web 服务)填充磁贴

Populating Tile From LINQ Query (Web Service)

我目前正在从硬编码数据填充我的 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 条信息,即 TitleDescriptionAuthor。我遇到的问题是将这 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;
    }

试试这个

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Linq;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            PrimaryTile pt = new PrimaryTile() {
                time = DateTime.Parse("11/21/2015 8:15 AM"),
                message = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore.",
                message2 = " 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.",
                branding = "name",
                appName = "HoL"
            };
            XmlDocument doc = CreateTiles(pt);

        }
        public static 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))
                                       )
                                  )
                             )
                        )
                    )
                );
            XmlDocument xmlDoc = new XmlDocument();
            xmlDoc.LoadXml(xDoc.ToString());
            return xmlDoc;
        }

    }
    public class PrimaryTile
    {
        public DateTime time { get; set; } 
        public string message { get; set; }
        public string message2 { get; set; }
        public string branding { get; set; }
        public string appName { get; set; }
    }

}
​