none
How to assign the ItemTemplate of a ListView dynamically in code?

    Question

  • Hi,

    I have a ListView that presents data based on a StaticResource Template ("DataListView").

    Current ListView XAML is below:

                 <ListView x:Name="DataListView"
                 	ItemsSource="{Binding}"
                 	ItemTemplate="{StaticResource DataTemplate}"
                    SelectionMode="Single"
                      ScrollViewer.VerticalScrollBarVisibility="Auto"
                    	HorizontalContentAlignment="Left"
                 	VerticalContentAlignment="Top"
                 	HorizontalAlignment="Left"
                 	VerticalAlignment="Top"
                 	Grid.Row="1"
                 	Margin="0,5,0,0" />

    I would like to set the ListView's ItemTemplate dynamically in my code. In design time I plan to prepare a few templates: DataTemplate1, DataTemplate2, DataTemplate2, etc. In run time I would like the application to be able to switch between them.

    Can it be done, and if so how?

    Thanks
    EitanB







    • Edited by eitanb Sunday, December 02, 2012 10:41 PM
    Sunday, December 02, 2012 9:39 PM

Answers

All replies