0
我目前正在從硬編碼的數據中填充我的Windows圖塊(我想確保我可以先讓它工作......)。我有...它對硬編碼信息非常有用。從LINQ查詢填充圖塊(Web服務)
我期望嘗試做的是從我的LINQ查詢中提取信息並將它們放入幾個變量中,然後將這些變量放入Tile中。
我使用網絡服務來聯繫我的SQL數據庫,並提供了和我有什麼如下:
Web服務
[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;
}
我想我們可能會有一個誤解......我試圖從我的LINQ查詢結果分配給變量。 – Code
我試過回答:我的問題是我不確定如何使用我的LINQ查詢結果將它們分配給PrimaryTile中的變量。我添加更多的代碼來查看我是否可以回答問題。 – jdweng
我在PrimaryTile中看不到以下三個屬性:標題,說明和作者。所以我不知道你想要什麼。我使用了'新的PrimaryTile'語句來創建PrimaryTile()並將合適的值設置爲值。 – jdweng