Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create ListBox.Itemtemplate,datatemplate programatically in Windows Phone 7

I find that there is some item templates, data templates and binding in the .xaml file for listbox. Is there any way to create it in code behind?

Is there any way to create data templates programataically?

this is the XAML CODE,BUT I need in code behind using c# not in XAML,because am working in dynamic list box creation with adding itemtemplatem,datatemplate

<ListBox Height="520" HorizontalAlignment="Left" Margin="0,6,0,0" Name="lstimge" VerticalAlignment="Top" Width="450" >
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <StackPanel Orientation="Horizontal">
                            <Image  Source="{Binding Image}" Width="150" Stretch="Uniform" HorizontalAlignment="Center" />
                            <TextBlock Text="{Binding FileName}" TextWrapping="Wrap" />
                        </StackPanel>
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>

Kindly give the solution

Thanks, Ashok

like image 438
Ash Avatar asked May 09 '11 06:05

Ash


1 Answers

You can't build templates from code - this can only be done from XAML.

If you dynamically generated the template XAML in your code, you could load it as described here.

I suspect you'll find yourself opening a whole can of worms if you go down this route. As an alternative, you could predefine a set of templates, and choose the correct one dynamically at runtime, as described here

like image 174
Damian Avatar answered Sep 30 '22 13:09

Damian