Note that there are some explanatory texts on larger screens.

plurals
  1. POWindows Phone 8: How to Bind from ICollection
    text
    copied!<p>I'm on windows phone 8 project and i'm new on this platform.</p> <p>I was doing binding from xaml side very well but i generated another new web api classes and i couldn't bind any item from ICollection.</p> <p>Here is my webapi.cs class ; </p> <pre><code> public class General { public Team Team { get; set; } public int Position { get; set; } public int LastPosition { get; set; } public int Played { get; set; } public int Won { get; set; } public int Draw { get; set; } public int Lost { get; set; } public int Scored { get; set; } public int Against { get; set; } public int Average { get; set; } public double Points { get; set; } public int SetsWon { get; set; } public int SetsLost { get; set; } public int SetAverage { get; set; } public double WinningPercentage { get; set; } public string Description { get; set; } public double? GamesBehind { get; set; } } public class Team { public int Sport { get; set; } public int ID { get; set; } public string Name { get; set; } public string ShortName { get; set; } public bool HasLogo { get; set; } } public class LeagueName { public Stage Stage { get; set; } public List&lt;General&gt; General { get; set; } public List&lt;Home&gt; Home { get; set; } public List&lt;Away&gt; Away { get; set; } public GroupedRows GroupedRows { get; set; } public GroupedRowsHome GroupedRowsHome { get; set; } public GroupedRowsAway GroupedRowsAway { get; set; } public List&lt;GroupType&gt; GroupTypes { get; set; } public List&lt;string&gt; Descriptions { get; set; } } public class RootObject { public ICollection&lt;LeagueName&gt; LeagueNames { get; set; } } </code></pre> <p>And here is how am i trying to bind ;</p> <pre><code>&lt;!--LayoutRoot is the root grid where all page content is placed--&gt; &lt;Grid x:Name="LayoutRoot" Background="Transparent"&gt; &lt;Grid.RowDefinitions&gt; &lt;RowDefinition Height="Auto"/&gt; &lt;RowDefinition Height="*"/&gt; &lt;/Grid.RowDefinitions&gt; &lt;!--TitlePanel contains the name of the application and page title--&gt; &lt;StackPanel x:Name="LeagueTable" Grid.Row="0" Margin="12,17,0,28" DataContext="{Binding LeagueNames}"&gt; &lt;TextBlock Text="{Binding General.Position}" Style="{StaticResource PhoneTextNormalStyle}"/&gt; &lt;TextBlock Text="{Binding General.Played}" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/&gt; &lt;/StackPanel&gt; &lt;/Grid&gt; </code></pre> <p>But in debug mode, it always says this error when i click related place;</p> <pre><code>System.Windows.Data Error: BindingExpression path error: 'General' property not found on 'System.Collections.Generic.List`1[WinPhone8try1.Apis.LeagueDetailApi+LeagueName]' 'System.Collections.Generic.List`1[WinPhone8try1.Apis.LeagueDetailApi+LeagueName]' (HashCode=17778899). BindingExpression: Path='General.Position' DataItem='System.Collections.Generic.List`1[WinPhone8try1.Apis.LeagueDetailApi+LeagueName]' (HashCode=17778899); target element is 'System.Windows.Controls.TextBlock' (Name=''); target property is 'Text' (type 'System.String').. </code></pre> <p>Please help me about it people. Thank you too much.</p> <p><strong>UPDATE</strong></p> <pre><code> &lt;phone:PhoneApplicationPage x:Class="WinPhone8try1.LeagueDetail" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone" xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" FontFamily="{StaticResource PhoneFontFamilyNormal}" FontSize="{StaticResource PhoneFontSizeNormal}" Foreground="{StaticResource PhoneForegroundBrush}" SupportedOrientations="Portrait" Orientation="Portrait" mc:Ignorable="d" shell:SystemTray.IsVisible="True" DataContext="{Binding LeagueName[]}"&gt; &lt;!--LayoutRoot is the root grid where all page content is placed--&gt; &lt;Grid x:Name="LayoutRoot" Background="Transparent"&gt; &lt;Grid.RowDefinitions&gt; &lt;RowDefinition Height="Auto"/&gt; &lt;RowDefinition Height="*"/&gt; &lt;/Grid.RowDefinitions&gt; &lt;!--TitlePanel contains the name of the application and page title--&gt; &lt;ListBox x:Name="LeagueTable" Grid.Row="0" Margin="12,17,0,28"&gt; &lt;ListBox.ItemTemplate&gt; &lt;DataTemplate&gt; &lt;ListBox&gt; &lt;ListBox.ItemTemplate&gt; &lt;DataTemplate&gt; &lt;StackPanel&gt; &lt;TextBlock Text="{Binding General.Position}" Style="{StaticResource PhoneTextNormalStyle}"/&gt; &lt;TextBlock Text="{Binding General.Played}" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/&gt; &lt;/StackPanel&gt; &lt;/DataTemplate&gt; &lt;/ListBox.ItemTemplate&gt; &lt;/ListBox&gt; &lt;/DataTemplate&gt; &lt;/ListBox.ItemTemplate&gt; &lt;/ListBox &gt; &lt;/Grid&gt; &lt;phone:PhoneApplicationPage.ApplicationBar&gt; &lt;shell:ApplicationBar IsVisible="True" IsMenuEnabled="True"&gt; &lt;shell:ApplicationBarIconButton IconUri="Images/appbar_back.png" Text="Geri" Click="ApplicationBarIconButton_Click_1"/&gt; &lt;/shell:ApplicationBar&gt; &lt;/phone:PhoneApplicationPage.ApplicationBar&gt; &lt;/phone:PhoneApplicationPage&gt; </code></pre> <p>I made the bindings like this. There is no error but nothing is displaying on screen. Can you help me about it please my friend ?</p> <p><strong>UPDATE 2</strong></p> <pre><code>&lt;ListBox x:Name="LeagueTable" Grid.Row="0" Margin="12,17,0,28"&gt; &lt;ListBox.ItemTemplate&gt; &lt;DataTemplate&gt; &lt;ListBox ItemsSource="{Binding General[]}"&gt; &lt;ListBox.ItemTemplate&gt; &lt;DataTemplate&gt; &lt;StackPanel&gt; &lt;TextBlock Text="{Binding Team.Name}" Style="{StaticResource PhoneTextNormalStyle}"/&gt; &lt;TextBlock Text="{Binding Team.Played}" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/&gt; &lt;/StackPanel&gt; &lt;/DataTemplate&gt; &lt;/ListBox.ItemTemplate&gt; &lt;/ListBox&gt; &lt;/DataTemplate&gt; &lt;/ListBox.ItemTemplate&gt; &lt;/ListBox&gt; </code></pre> <p>namespace WinPhone8try1 { public partial class LeagueDetail : PhoneApplicationPage { private string json = ""; private LeagueDetailApi.LeagueName[] leaguedetail { get; set; }</p> <pre><code> public LeagueDetail() { InitializeComponent(); DataContext = new LeagueDetailApi.LeagueName(); } protected override void OnNavigatedTo(NavigationEventArgs e) { string selectedItem = NavigationContext.QueryString["selectedIndex"]; int index = int.Parse(selectedItem); string url = "MY API URL; HttpWebRequest hWebRequest = (HttpWebRequest) HttpWebRequest.Create(url); hWebRequest.Method = "GET"; hWebRequest.BeginGetResponse(LeagueTable_Load_Completed, hWebRequest); } private void LeagueTable_Load_Completed(IAsyncResult ar) { HttpWebRequest request = (HttpWebRequest) ar.AsyncState; HttpWebResponse response = (HttpWebResponse) request.EndGetResponse(ar); using (StreamReader streamReader = new StreamReader(response.GetResponseStream())) { json = streamReader.ReadToEnd(); leaguedetail = JsonConvert.DeserializeObject&lt;LeagueDetailApi.LeagueName[]&gt;(json); } Deployment.Current.Dispatcher.BeginInvoke(() =&gt; { LeagueTable.DataContext = leaguedetail.ToList(); }); } private void ApplicationBarIconButton_Click_1(object sender, EventArgs e) { NavigationService.GoBack(); } } </code></pre> <p>}</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload