开发者

generate Grid from template

Howdy, I've got another question regarding phone 7... I want to generate a couple of Grids in a stackpanel - since they all have the same layout I thought it would be a great idea to use DataTemplates ...

But then I found that the GRID Object has no "DataTemplate" Property and now I'm kinda stuck ... the template which I use is the following:

        <DataTemplate x:Key="Speise">
            <Grid>
                <TextBlock Height="36" Margin="8,43,104,0" TextWrapping="Wrap" Text="TextBlock" VerticalAlignment="Top"/>
                <TextBlock HorizontalAlignment="Right" Hei开发者_Python百科ght="36" Margin="0,44,8,0" TextWrapping="Wrap" Text="TextBlock" VerticalAlignment="Top" Width="92"/>
            </Grid>
        </DataTemplate>

The way I now thought of creating my objects is:

Grid blubber = (Grid)this.Resources["Speise"];

But that is not working ... I think it's again a really short thing, but I have no clue of how to google for it :(


On the phone the Grid does not support data templating as it's purely intented as a container for layout.

Outside of the phone, Silverlight has a DataGrid class which you could use this way but it's not available on WP7.

If you want a simple way of generating a large grid you could look at generating something in code using nested loops to create the rows and columns. Without knowing precisely what you're trying to achieve it's hard to advise further.

Also, in your sample DataTemplate you are using a grid just to hold 2 TextBlocks. This seems overly complex. Would a StackPanel (or something else) not be more appropriate?


You could use ListBox as your container rather than StackPanel. It supports a DataTemplate as you can see here.

binding a Linq datasource to a listbox

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜