简体   繁体   English

如何在运行时更改Listbox的'DataTemplate方向?

[英]How can I change a Listbox's' DataTemplate orientation at runtime?

I am recently trying to learn WinRT and Xaml, and I stumbled upong this issue: 我最近正在尝试学习WinRT和Xaml,我偶然发现了这个问题:

I have this fragment of code: 我有这段代码:

<ListBox Grid.Row="1" x:Name="imageListBox" Height="721">
        <ListBox.ItemTemplate>
            <DataTemplate>
                <StackPanel x:Name="imageListBoxStackPanelTemplate" HorizontalAlignment="Center">
                    <Image Source="{Binding url}"/>
                </StackPanel>
            </DataTemplate>
        </ListBox.ItemTemplate>
    </ListBox>

which is bound to an ObservableCollection, and displays the images vertically. 绑定到ObservableCollection,并垂直显示图像。 I'd like to be able to change the orientation (the flow direction) of the images from Vertical to Horizontal upong pressing a Button, at runtime. 我希望能够在运行时按下按钮将图像的方向(流向)从垂直更改为水平。

I've tried several solutions without any luck, so I hope someone of you could lend me an hand. 我已经尝试了几个没有运气的解决方案,所以我希望你们中的某个人可以伸出援助之手。 Thanks! 谢谢! :) :)

You can use two listbox, having different orientation. 您可以使用两个具有不同方向的列表框。 One is visible another collapsed. 一个是可见的另一个崩溃。 Click on the button swap the visibility. 单击按钮交换可见性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在WPF中访问列表框中的数据模板中的控件 - How Can I Access to The Controls in DataTemplate in ListBox in WPF 如何使用DataTemplate实现对WPF ListBox的搜索? - How can I implement search for a WPF ListBox with DataTemplate? 以编程方式更改ListBox DataTemplate - Programmatically change ListBox DataTemplate 如何在XAML中访问ListBox的DataTemplate(但不是Binding)中的TextBlock? - How do I access a TextBlock which is inside my ListBox's DataTemplate (but not Binding) in XAML? 如何在运行时更改页面的母版页? - How can I change my page's Master Page at runtime? 如何更改特定单元格的DataGridTemplateColumn DataTemplate元素的属性 - How can I change the properties of a DataGridTemplateColumn DataTemplate Element for a specific cell 如何根据元素类型更改代码中列表框的datatemplate? - How to change datatemplate of listbox in code depending on element type? 我怎样才能{x:绑定}到UWP中的DataTemplate的根类型? - How can I {x:Bind} to a DataTemplate's root type in UWP? 如何获取代码中DataTemplate的x:Key? - How can I obtain a DataTemplate's x:Key in code? DataType的DataTemplate - 如何在特定的ListBox中覆盖此DataTemplate? - DataTemplate for a DataType - how to override this DataTemplate in a particular ListBox?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM