I have this code on my xaml and works fine (ListView component)
<ListView.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal"></StackPanel>
</ItemsPanelTemplate>
I´m trying to replicate on code behind using this answer Create DataTemplate in code behind, but i could not make it work (the Russell´s answer). Any help will be appreciated. Thanks!
Edit:
ListView listView = new ListView();
listView.ItemsPanel = GetItemsPanelTemplate();
private ItemsPanelTemplate GetItemsPanelTemplate()
{
string xaml = @"<ItemsPanelTemplate xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'>
<ListView.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation=""Horizontal""></StackPanel>
</ItemsPanelTemplate>
</ListView.ItemsPanel>
</ItemsPanelTemplate>";
return XamlReader.Parse(xaml) as ItemsPanelTemplate;
}