开发者

why i couldn't see any data in WPF Grid?

    <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开发者_C百科" 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.


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}"

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜