拉伸/设置图块以适合 ListView
我已经使用基于 http://msdn.microsoft 的代码实现了 ListView 的自定义视图.com/en-us/library/ms748859.aspx
在“TileView”中,我如何设置 ListView 来拉伸每个图块以适应可用空间。即,即使 ListView 更改大小,也可以在 ListView 中精确地容纳 3 列(即保持每个图块始终为 1/3 宽)
<l:PlainView x:Key="tileView" ItemTemplate="{StaticResource centralTile}" />
<DataTemplate x:Key="centralTile">
<StackPanel>
<Grid HorizontalAlignment="Center">
<Image Source="{Binding XPath=@Image}" />
</Grid>
<TextBlock Text="{Binding XPath=@Name}" />
<TextBlock Text="{Binding XPath=@Type}" />
</StackPanel>
</DataTemplate>
编辑:
我已经使用上面的方法让 ListView 显示 x 个图块,并在该示例中更改以下 XAML:
<Setter Property="ItemsPanel">
<Setter.Value>
<ItemsPanelTemplate>
<WrapPanel Width="{Binding (FrameworkElement.ActualWidth),
RelativeSource={RelativeSource
AncestorType=ScrollContentPresenter}}"
ItemWidth="{Binding (ListView.View).ItemWidth,
RelativeSource={RelativeSource AncestorType=ListView}}"
MinWidth="{Binding (ListView.View).ItemWidth,
RelativeSource={RelativeSource AncestorType=ListView}}"
ItemHeight="{Binding (ListView.View).ItemHeight,
RelativeSource={RelativeSource AncestorType=ListView}}"/>
</ItemsPanelTemplate>
</Setter.Value>
</Setter>
<Setter Property="ItemsPanel">
<Setter.Value>
<ItemsPanelTemplate>
<UniformGrid Columns="3"/>
</ItemsPanelTemplate>
</Setter.Value>
</Setter>
这正是我需要的,如果 ListView 调整列大小,则列将调整大小。 现在我还
需要弄清楚如何动态更改 UniformGrid 列:)
I've implemented custom view for ListView using code based on http://msdn.microsoft.com/en-us/library/ms748859.aspx
In the 'TileView" how would I set ListView to stretch each tile to fit the available space. I.e. fit exactly 3 columns in the ListView even if the ListView changes size (i.e. keep each tile always 1/3 wide).
<l:PlainView x:Key="tileView" ItemTemplate="{StaticResource centralTile}" />
<DataTemplate x:Key="centralTile">
<StackPanel>
<Grid HorizontalAlignment="Center">
<Image Source="{Binding XPath=@Image}" />
</Grid>
<TextBlock Text="{Binding XPath=@Name}" />
<TextBlock Text="{Binding XPath=@Type}" />
</StackPanel>
</DataTemplate>
Edit:
I have got the ListView to display x tiles using the above and changing the following XAML in that example:
<Setter Property="ItemsPanel">
<Setter.Value>
<ItemsPanelTemplate>
<WrapPanel Width="{Binding (FrameworkElement.ActualWidth),
RelativeSource={RelativeSource
AncestorType=ScrollContentPresenter}}"
ItemWidth="{Binding (ListView.View).ItemWidth,
RelativeSource={RelativeSource AncestorType=ListView}}"
MinWidth="{Binding (ListView.View).ItemWidth,
RelativeSource={RelativeSource AncestorType=ListView}}"
ItemHeight="{Binding (ListView.View).ItemHeight,
RelativeSource={RelativeSource AncestorType=ListView}}"/>
</ItemsPanelTemplate>
</Setter.Value>
</Setter>
<Setter Property="ItemsPanel">
<Setter.Value>
<ItemsPanelTemplate>
<UniformGrid Columns="3"/>
</ItemsPanelTemplate>
</Setter.Value>
</Setter>
This is exactly what I need where if the ListView resizes the columns will resize as well.
Now I need to figure out how to change the UniformGrid Columns dynamically :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我对这个主题有两个考虑:
它正在工作演示,但您应该根据您的要求改进 MyPanel:
XAML 中的用法:
I have two consideration on subject:
It's working demonstration but you should improve MyPanel according to your requirements:
Usage in XAML: