i want to create horizontal list with these uielements in wpf.I already use listview like
<ListView Name="marqueeList" Height="300" Width="1000" ItemsSource="{Binding}">
<ListView.ItemsPanel>
<ItemsPanelTemplate>
<VirtualizingStackPanel Orientation="Horizontal">
<Virtual开发者_Go百科izingStackPanel Orientation="Vertical">
<VirtualizingStackPanel>
<Label Name="CompanyName" FontWeight="Bold" Content="{Binding CompanyName}"></Label>
</VirtualizingStackPanel>
<VirtualizingStackPanel Orientation="Horizontal">
<Label Name="CurrentPrice" Content="{Binding CurrentPrice}" ></Label>
<Label Name="Deviation" Content="{Binding Deviation}"></Label>
</VirtualizingStackPanel>
</VirtualizingStackPanel>
</VirtualizingStackPanel>
</ItemsPanelTemplate>
</ListView.ItemsPanel>
</ListView>
but its throwing an exception "VisualTree of ItemsPanelTemplate must be a single element." Please help on this
To make your listview horizontal do this.
<ListView Name="marqueeList" ItemTemplate="{StaticResource myListViewTemplate}" ItemsSource="{Binding}">
<ListView.ItemsPanel>
<ItemsPanelTemplate>
<VirtualizingStackPanel Orientation="Horizontal"></VirtualizingStackPanel>
</ItemsPanelTemplate>
</ListView.ItemsPanel>
</ListView>
You can put all your other content into a DataTemplate
<DataTemplate x:Key="myListViewTemplate">
<StackPanel>
<StackPanel>
<Label Name="CompanyName" FontWeight="Bold" Content="{Binding CompanyName}"/>
</StackPanel>
<StackPanel>
<Label Name="CurrentPrice" Content="{Binding CurrentPrice}"/>
<Label Name="Deviation" Content="{Binding Deviation}"/>
</StackPanel>
</StackPanel>
</DataTemplate>
精彩评论