开发者

how can i bind my ui elements horizentally in wpf?

开发者 https://www.devze.com 2023-01-02 00:58 出处:网络
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}\">

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>
0

精彩评论

暂无评论...
验证码 换一张
取 消