在 UWP 是不支持在 Setter 里面的 Value 进行绑定,如果想要在 ItemsPanelTemplate 里面绑定显示方向,那么需要通过附加属性的方法绑定。 Orientation 绑定到 ListView 的 ItemsPanel 通过一个样式 <Setter Property="ItemsPanel"> <Setter.Value> <ItemsPanelTemplate Orientation="{Binding Orientation, RelativeSource={RelativeSource Mode=TemplatedParent}}"/> </ItemsPanelTemplate Orientation, RelativeSource={RelativeSource Mode=TemplatedParent}}"/> </ItemsPanelTemplate > <ItemsStackPanel /> </ItemsPanelTemplate
在 UWP 是不支持在 Setter 里面的 Value 进行绑定,如果想要在 ItemsPanelTemplate 里面绑定显示方向,那么需要通过附加属性的方法绑定。 Orientation 绑定到 ListView 的 ItemsPanel 通过一个样式 <Setter Property="ItemsPanel"> <Setter.Value> <ItemsPanelTemplate Orientation="{Binding Orientation, RelativeSource={RelativeSource Mode=TemplatedParent}}"/> </ItemsPanelTemplate Orientation, RelativeSource={RelativeSource Mode=TemplatedParent}}"/> </ItemsPanelTemplate > <ItemsStackPanel /> </ItemsPanelTemplate
class TestData{public string d{set;get;}} } 这里我们借助VisualTreeHelper对指定行(ListBoxItem)做了一个遍历,以查找符合要求的控件 对于ItemsPanelTemplate 中的命名控件,比如下面这样的: <ListBox> <ItemsPanelTemplate> <StackPanel Orientation="Horizontal" x:Name="sp"></StackPanel > </ItemsPanelTemplate> <ListBox.ItemTemplate> <DataTemplate> <Rectangle Width="100" Height="100 </ListBox> 如果想在listItem_MouseLeftButtonDown中引用sp,按正统处理方法还真是比较麻烦(各位可以google,baidu印证),这里给出一个很取巧的办法: <<em>ItemsPanelTemplate</em> > <StackPanel Orientation="Horizontal" x:Name="sp" Loaded="sp_Loaded"></StackPanel> </ItemsPanelTemplate
listbox大家都会用,如果要让它支持换行操作还必须加上 ListBox.ItemsPanel ItemsPanelTemplate toolkit:WrapPanel/ /ItemsPanelTemplate 这样的后果可能会出现要么全部推在一起,要么要有横向的滚动条 listbox大家都会用,如果要让它支持换行操作还必须加上 <ListBox.ItemsPanel> <ItemsPanelTemplate > <WrapPanel ></WrapPanel> </ItemsPanelTemplate>
ClusterPanel MaxLevel="3" Orientation="Horizontal"></series:ClusterPanel> </ItemsPanelTemplate ElementName=verBorder}"> <ItemsControl.ItemsPanel> <ItemsPanelTemplate ClusterPanel MaxLevel="3" Orientation="Vertical"></series:ClusterPanel> </ItemsPanelTemplate "ContentItemsControl"> <ItemsControl.ItemsPanel> <ItemsPanelTemplate <ItemsControl.ItemsPanel> <ItemsPanelTemplate
可以使用下面代码 <ListView.ItemsPanel> <ItemsPanelTemplate> < StackPanel Orientation="Horizontal"></StackPanel> </ItemsPanelTemplate> < ScrollViewer.VerticalScrollMode="Disabled"> 使用从左到右放元素 实际上 ItemsPanelTemplate 可以放很多个类型,如 WrapGrid 和 ItemsWrapGrid ,下面我告诉大家如何做出这个效果 <ListView.ItemsPanel> <ItemsPanelTemplate <ItemsWrapGrid Orientation="Horizontal"></ItemsWrapGrid> </ItemsPanelTemplate
可以通过使用 WrapPanel 让控件,如果宽度在 ListView 或 ListBox 之外就换行 <ListView.ItemsPanel> <ItemsPanelTemplate > <WrapPanel Orientation="Horizontal"></WrapPanel> </ItemsPanelTemplate 看起来大概是下面代码 <ListView ScrollViewer.HorizontalScrollBarVisibility="Disabled"> <ListView.ItemsPanel> <ItemsPanelTemplate > <WrapPanel Orientation="Horizontal" /> </ItemsPanelTemplate> </ListView.ItemsPanel> .
本文告诉大家如何在代码动态修改 ListView 的元素布局,从垂直修改为水平,从水平修改为垂直 先给大家一张图看一下效果 如何需要从 cs 代码修改 ListView 的 ItemsPanel 的 ItemsPanelTemplate <ListView.ItemsPanel> <ItemsPanelTemplate> <ItemsStackPanel Orientation="Horizontal "/> </ItemsPanelTemplate> </ListView.ItemsPanel> 因为无法通过后台代码直接创建一个 ItemsPanelTemplate ,除了使用
如何需要从 cs 代码修改 ListView 的 ItemsPanel 的 ItemsPanelTemplate 从而修改元素布局是比较困难的。 <ListView.ItemsPanel> <ItemsPanelTemplate> <ItemsStackPanel Orientation="Horizontal "/> </ItemsPanelTemplate> </ListView.ItemsPanel> 因为无法通过后台代码直接创建一个 ItemsPanelTemplate ,除了使用
上面代码运行可以看到列表是垂直的 如果需要修改为水平的,可以通过 ItemsPanel 修改 <ListView.ItemsPanel> <ItemsPanelTemplate > <StackPanel Orientation="Horizontal" /> </ItemsPanelTemplate> Source={StaticResource InventoryData}, XPath=Book}"> <ListView.ItemsPanel> <ItemsPanelTemplate > <StackPanel Orientation="Horizontal" /> </ItemsPanelTemplate>
如果需要修改为水平的,可以通过 ItemsPanel 修改 <ListView.ItemsPanel> <ItemsPanelTemplate> <StackPanel Orientation="Horizontal" /> </ItemsPanelTemplate> Source={StaticResource InventoryData}, XPath=Book}"> <ListView.ItemsPanel> <ItemsPanelTemplate > <StackPanel Orientation="Horizontal" /> </ItemsPanelTemplate>
VariableSizedWrapGrid Orientation="Vertical" Margin="0 0 0 20" ItemHeight="75"/> </ItemsPanelTemplate </GroupStyle> </ListView.GroupStyle> <ListView.ItemsPanel> <ItemsPanelTemplate > <StackPanel Orientation="Vertical" /> </ItemsPanelTemplate> DataTemplate> </ListView.ItemTemplate> <ListView.ItemsPanel> <ItemsPanelTemplate > <StackPanel Orientation="Vertical"/> </ItemsPanelTemplate>
DataTemplate> </ListBox.ItemTemplate> <ListBox.ItemsPanel> <ItemsPanelTemplate > <StackPanel Orientation="Horizontal" Margin="10"/> </ItemsPanelTemplate </telerik:ListBox.ItemTemplate> <telerik:ListBox.ItemsPanel> <ItemsPanelTemplate > <StackPanel Orientation="Horizontal" Margin="10"/> </ItemsPanelTemplate
可以通过使用 WrapPanel 让控件,如果宽度在 ListView 或 ListBox 之外就换行 <ListView.ItemsPanel> <ItemsPanelTemplate > <WrapPanel Orientation="Horizontal"></WrapPanel> </ItemsPanelTemplate 看起来大概是下面代码 <ListView ScrollViewer.HorizontalScrollBarVisibility="Disabled"> <ListView.ItemsPanel> <ItemsPanelTemplate > <WrapPanel Orientation="Horizontal" /> </ItemsPanelTemplate> </ListView.ItemsPanel> .
Source={StaticResource InventoryData}, XPath=Book}"> <ListView.ItemsPanel> <ItemsPanelTemplate > <StackPanel Orientation="Horizontal" /> </ItemsPanelTemplate>
--横向布局--> <ItemsPanelTemplate x:Key="HorizontalItemsPanelTemplate"> <VirtualizingStackPanel ScrollViewer.HorizontalScrollMode="Enabled" ScrollViewer.VerticalScrollMode="Disabled"/> </ItemsPanelTemplate --横向布局--> <ItemsPanelTemplate x:Key="HorizontalItemsPanelTemplate"> <VirtualizingStackPanel ScrollViewer.HorizontalScrollMode="Enabled" ScrollViewer.VerticalScrollMode="Disabled"/> </ItemsPanelTemplate
ListView.ItemTemplate> <ListView.ItemsPanel> <ItemsPanelTemplate <WrapPanel IsItemsHost=”True” Orientation=”Horizontal” /> </ItemsPanelTemplate
可以使用下面代码 <ListView.ItemsPanel> <ItemsPanelTemplate> < StackPanel Orientation="Horizontal"></StackPanel> </ItemsPanelTemplate> < ScrollViewer.VerticalScrollMode="Disabled"> 使用从左到右放元素 实际上 ItemsPanelTemplate 可以放很多个类型,如 WrapGrid 和 ItemsWrapGrid ,下面我告诉大家如何做出这个效果 <ListView.ItemsPanel> <ItemsPanelTemplate <ItemsWrapGrid Orientation="Horizontal"></ItemsWrapGrid> </ItemsPanelTemplate
思路是: 修改ItemTemplate样式 ItemsPanelTemplate 用WrapPanel显示 先为image绑定图片添加一个转换类 using System; ControlTemplate> </Setter.Value> </Setter> </Style> listbox用的时候要把它的ItemsPanelTemplate ItemTemplate="{StaticResource ItemTemplate}"> <ListBox.ItemsPanel> <ItemsPanelTemplate WrapPanel Width="Auto" Background="#F3FFFF" > </tools:WrapPanel> </ItemsPanelTemplate WrapPanel Width="Auto" Background="#F3FFFF" > </tools:WrapPanel> </ItemsPanelTemplate
ItemsControl ItemsSource="{Binding NestGroups}"> 18 <ItemsControl.ItemsPanel> 19 <ItemsPanelTemplate > 20 <StackPanel Orientation="Horizontal"></StackPanel> 21 </ItemsPanelTemplate {Binding LeftTubes3}"> 30 <ItemsControl.ItemsPanel> 31 <ItemsPanelTemplate > 32 <Canvas/> 33 </ItemsPanelTemplate> 34 " Rows="{Binding Cols}" IsHitTestVisible="False"/> 56 </ItemsPanelTemplate