![](/img/trans.png)
[英]How to bind muliple row result in single data binding in Windows store app in C#/XAML
[英]How to Bind JSON data through Web API(Online Services) with xaml UI In Windows Store App?
我正在Windows 8中開發我的第一個應用程序。我從Windows 8的第9頻道看到了教程http://channel9.msdn.com/Series/Windows-Store-apps-for-Absolute-Beginners-with-C-#制作一個演示應用程序,其中數據通過Web服務傳遞,但是我無法為通過Web Service接收的JSON數據創建DataSource.cs文件。
這是我的JSON數據來自Web服務。
[
{
"id": "1",
"title": "Test_rom",
"subtitle": "",
"icon": "http://lpl.info/Admin/upload/cat.1.png"
},
{
"id": "2",
"title": "Jewelry",
"subtitle": "",
"icon": "http://lpl.info/Admin/upload/cat.2.png"
},
{
"id": "3",
"title": "Jackets",
"subtitle": "All sizes available",
"icon": "http://lpl.info/Admin/upload/cat.3.png"
},
{
"id": "4",
"title": "Dresses",
"subtitle": "",
"icon": "http://lpl.info/Admin/upload/cat.4.png"
},
{
"id": "5",
"title": "Bags",
"subtitle": "",
"icon": "http://lpl.info/Admin/upload/cat.5.png"
},
{
"id": "6",
"title": "Watches",
"subtitle": "",
"icon": "http://lpl.info/Admin/upload/cat.6.png"
},
{
"id": "8",
"title": "Glasses",
"subtitle": "",
"icon": "http://lpl.info/Admin/upload/cat.8.png"
}
]
現在,我想為這些組類別JSON數據創建一個網格模板。 但是,我是該領域的新手,因此嘗試將其與XAML UI綁定,但是失敗了。
我嘗試了很多相關代碼,但所有代碼都適用於Windows Phone 8,而我想要適用於Windows 8 Metro Application。
這些是XAML中讓我感到困惑的代碼。
<Page.Resources>
<CollectionViewSource
x:Name="groupedItemsViewSource"
Source="{Binding Groups}"
IsSourceGrouped="true"
ItemsPath="Items"
d:Source="{Binding Groups, Source={d:DesignInstance Type=local:RootObject, CreateList=True}}"/>
</Page.Resources>
和
protected override void LoadState(Object navigationParameter, Dictionary<string,> pageState)
{
OsCatalogData os = new OsCatalogData();
os.GetJson(Constants.OscatalogMenulist, "HomePagemenu");
// TODO: Create an appropriate data model for your problem domain to replace the sample data
this.DefaultViewModel["Group"] = os.?????;
}
我試圖從很多天開始進行開發。 誰能幫忙? 我不想要完整的代碼,但是我可以在哪里滿足我的要求...。
提前致謝....
我對您的問題的理解是-您在解析要使用的json數據時遇到問題。希望我是對的-
1
=>安裝Newtonsoft.json nuget軟件包。 它將用於高效且易於使用的json解析。
2
=>現在創建一個RootObject類(相應地命名-這是一個簡單的Data Parser類)。
public class RootObject
{
public string id { get; set; }
public string title { get; set; }
public string subtitle { get; set; }
public string icon { get; set; }
}
3
=>現在,您的Json表示這些類對象的列表/數組,實際上是您的json類型是List,所以可以這樣解析。
var groups= JsonConvert.DeserializeObject<List<RootObject>>(yourJson);
現在,您的組以C#類的形式包含數據,現在您可以根據需要使用它們。
閱讀此http://prathapk.net/using-web-api-in-windows-phone-8/和此http://www.asp.net/web-api/overview/advanced/calling-a-web-來自網絡客戶端的api
PS:綁定它們時,請使用“組”而不是“組”。 我希望這能幫到您。 在這里尋找類似的問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.