<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>
源代码
var Products = from t in bsEntity.ProductsTemps select t;
grdProduct.DataContext = Products;
谢谢。
答案 0 :(得分:3)
您需要将ItemsSource
的{{1}}属性绑定到集合。
同样在您的项目控件中,您已使用项目模板声明了额外的项目控件。
您正在寻找的是:
ItemsControl
另外,我认为你的网格上不需要<ItemsControl ItemsSource="{Binding Path=YourCollectionProperty}">
<ItemsControl.ItemTemplate>
<!--your data template here-->
</ItemsControl.ItemTemplate>
</ItemsControl>
。如果有的话,你可能需要DataContext="Binding"