Search code examples
c#xamlwindows-phone-8data-bindinglonglistselector

LongListSelector Data Binding Issue


I am a beginner in windows Windows phone programming. i am trying to implement LongListSelector to display group by products.

here are my classes :

public class ProductMaster {
    public string Name { get; set; }
    public List<ProductSubMaster> Models { get; set; }
}


public class ProductSubMaster
{
    public string Name { get; set; }
    public ProductSubMasterProperty modelProperty { get; set; }
}

public class ProductSubMasterProperty{
    public string ProNo { get; set; }
    public Uri ProImage { get; set; }

}

and my xaml :

 <phone:LongListSelector
                    x:Name="ProductList"
                    ItemsSource="{Binding  objProduct}"
                    Background="Transparent"
                    LayoutMode="List"
                    IsGroupingEnabled="True"
                    HideEmptyGroups ="False">
                    <phone:LongListSelector.GroupHeaderTemplate>
                        <DataTemplate>
                            <Border Background="Transparent" Padding="5">
                                <Border Background="Black" BorderBrush="Black" BorderThickness="2" Width="500" 
                                        Height="62" Margin="0,0,18,0" HorizontalAlignment="Left">
                                    <TextBlock Text="{Binding Path=[0].Name}" Foreground="White" FontSize="25" Padding="10" 
                                                FontFamily="{StaticResource PhoneFontFamilySemiLight}" HorizontalAlignment="Center" VerticalAlignment="Center"/>
                                </Border>
                            </Border>
                        </DataTemplate>
                    </phone:LongListSelector.GroupHeaderTemplate>
                    <phone:LongListSelector.ItemTemplate>
                        <DataTemplate>
                            <StackPanel Orientation="Horizontal">
                                <Image x:Name="searchimg" HorizontalAlignment="Left" VerticalAlignment="Center"  Margin="10,0,0,0" Source="{Binding Path=Models.modelProperty.ProImage}" Height="100" Width="100" ></Image>
                                <TextBlock x:Name="ProductName"  Margin="20,0,0,0"  HorizontalAlignment="Center" VerticalAlignment="Center" Width="250" TextWrapping="Wrap" Foreground="Black" Text="{Binding Path=Models.Name}" FontSize="30"></TextBlock>
                                <Image x:Name="bookmarkimg"  HorizontalAlignment="Right" Margin="0,0,0,0" VerticalAlignment="Center"  Source="/Assets/Media/star.png" Height="40" Width="30" Stretch="Uniform" ></Image>
                            </StackPanel>
                        </DataTemplate>
                    </phone:LongListSelector.ItemTemplate>
                </phone:LongListSelector>

i am facing the issue for binding ItemTemplate

Please help me out

Thank you.


Solution

  • i have added listbox in itemtemplate solved my issue

    here is my updated code

    <phone:LongListSelector.ItemTemplate>
                                <DataTemplate>
                                <ListBox x:Name="LstFeaturesData" Visibility="Visible" ItemsSource="{Binding Path=Models}" Margin="0,0">
                                        <ListBox.ItemTemplate>
                                            <DataTemplate>
                                                <StackPanel Orientation="Horizontal">
                                                    <Image x:Name="searchimg" HorizontalAlignment="Left" VerticalAlignment="Center"  Margin="10,0,0,0" Source="{Binding Path=modelProperty.ProImage}" Height="100" Width="100" ></Image>
                                                    <TextBlock x:Name="ProductName"  Margin="20,0,0,0"  HorizontalAlignment="Center" VerticalAlignment="Center" Width="250" TextWrapping="Wrap" Foreground="Black" Text="{Binding Path=Name}" FontSize="30"></TextBlock>
                                                    <Image x:Name="bookmarkimg"  HorizontalAlignment="Right" Margin="0,0,0,0" VerticalAlignment="Center"  Source="/Assets/Media/star.png" Height="40" Width="30" Stretch="Uniform" ></Image>
                                                </StackPanel>
                                            </DataTemplate>
                                        </ListBox.ItemTemplate>
                                    </ListBox>
                                </DataTemplate>
                            </phone:LongListSelector.ItemTemplate>