WPF change ItemsPanel and ItemTemplate in code behind

Posted by Tijs Hendriks on Stack Overflow See other posts from Stack Overflow or by Tijs Hendriks
Published on 2010-04-10T15:08:19Z Indexed on 2010/04/10 15:13 UTC
Read the original article Hit count: 818

Filed under:
|
|
|
|

Hi,

I have the following list in XAML:

<ListView Name="ListViewBack"
          Margin="3"
          ScrollViewer.HorizontalScrollBarVisibility="Disabled"
          ItemsPanel="{StaticResource IconListPanelTemplate}"
          ItemTemplate="{StaticResource IconListDataTemplate}">
</ListView>

Now I would like to be able to change the ItemsPanel and ItemTemplate from the List to the Grid version. I've tried this using the following code:

ListViewBack.ItemsPanel = Resources["IconGridPanelTemplate"] as ItemsPanelTemplate;
ListViewBack.ItemTemplate = Resources["IconGridDataTemplate"] as DataTemplate;

But nothing happens when excecuted.

Any idea's?

Thanks!

© Stack Overflow or respective owner

Related posts about wpf

Related posts about itemspanel