views:

36

answers:

1

    <DataTemplate x:Key="tmpGrdProducts">


        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition/>
                <RowDefinition/>
                <RowDefinition/>
                <RowDefinition/>
                <RowDefinition/>

            </Grid.RowDefinitions>

            <Grid.ColumnDefinitions>
                <ColumnDefinition/>
                <ColumnDefinition/>
                <ColumnDefinition/>
            </Grid.ColumnDefinitions>
            <Image Grid.RowSpan="6" Width="200" Height="200" Grid.Column="0" Grid.Row="0"></Image>
            <TextBlock Grid.ColumnSpan="2" Grid.Row="0" Grid.Column="1" Text="{Binding ProductName}" Foreground="Red"></TextBlock>

            <!-- Labels-->
            <TextBlock Text="SKU" Foreground="Red" Grid.Column="1" Grid.Row="1"></TextBlock>
            <TextBlock Text="Code" Foreground="Red" Grid.Column="1" Grid.Row="2"></TextBlock>
            <TextBlock Text="Mark" Foreground="Red" Grid.Column="1" Grid.Row="3"></TextBlock>
            <TextBlock Text="Model" Foreground="Red" Grid.Column="1" Grid.Row="4"></TextBlock>

            <!-- Data-->
            <TextBlock Text="{Binding SKU}" Foreground="Black" Grid.Column="1" Grid.Row="1"></TextBlock>
            <TextBlock Text="{Binding ProductCode}" Foreground="Black" Grid.Column="1" Grid.Row="2"></TextBlock>
            <TextBlock Text="{Binding Mark}" Foreground="Black" Grid.Column="1" Grid.Row="3"></TextBlock>
            <TextBlock Text="{Binding Model}" Foreground="Black" Grid.Column="1" Grid.Row="4"></TextBlock>

        </Grid>


    </DataTemplate>



</Page.Resources>


<Grid x:Name="grdProduct" DataContext="Binding">

    <ItemsControl>

        <ItemsControl ItemTemplate="{StaticResource tmpGrdProducts}"></ItemsControl>


    </ItemsControl>




</Grid>

source code

var Products = from t in bsEntity.ProductsTemps select t;

grdProduct.DataContext = Products;

thank you

+2  A: 

You need to bind the ItemsSource property of your ItemsControl to the collection. Also inside your items control, you've declared an extra items control with the item template.

What you're looking for is something like:

<ItemsControl ItemsSource="{Binding Path=YourCollectionProperty}">
    <ItemsControl.ItemTemplate>
         <!--your data template here-->
    </ItemsControl.ItemTemplate>
</ItemsControl>

Also, I don't think you want DataContext="Binding" on your grid. If at all you'll probably need DataContext="{Binding}"

Val
thank you. your answer saved my time.
Murat Cabuk
DataContext="{Binding}" is redundant. It's roughly equivalent to doing this.DataContext = this.DataContext in code.
John Bowen
@John Bowen. +1 for a Good point. Though since he was already attempting to set the datacontext the grid I thought i'd roll with it, not knowing the complete solution.
Val