如何在ListView中设置附加的网格属性。
如何设置附加属性grid.row =“?”
在dataTemplate内部标记的
?因此,listView
将以5个相等的行扩展项目。
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Setter Property="VerticalContentAlignment" Value="Stretch"/>
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
</Style>
</ListView.ItemContainerStyle>
<ListView.ItemsPanel>
<ItemsPanelTemplate>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
</Grid>
</ItemsPanelTemplate>
</ListView.ItemsPanel>
<ListView.ItemTemplate>
<DataTemplate>
<view:SingleChartView Grid.Row="?" />
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
How can I set the attachaed property Grid.Row="?"
marked beneath inside the DataTemplate
? So that the ListView
will stretch the items in 5 equal rows.
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Setter Property="VerticalContentAlignment" Value="Stretch"/>
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
</Style>
</ListView.ItemContainerStyle>
<ListView.ItemsPanel>
<ItemsPanelTemplate>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
</Grid>
</ItemsPanelTemplate>
</ListView.ItemsPanel>
<ListView.ItemTemplate>
<DataTemplate>
<view:SingleChartView Grid.Row="?" />
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尽管网格来自面板,但并非被设计用作包装盒的项目Spaneltemplate。
旧但相关: https://blog.scottlogic.com/2010/11/15/ususion-a-grid-as-the-panel-for-an-itemscontrol.html
底线,这在某种程度上需要才能动态创建行,并使用代码在后面应用网格的附加属性。
Although Grid derives from Panel, it is not designed to be used as an ItemsPanelTemplate out of the box.
Old but relevant: https://blog.scottlogic.com/2010/11/15/using-a-grid-as-the-panel-for-an-itemscontrol.html
Bottom line, this somewhat requires the ability to dynamically create rows, and also apply Grid's attached properties using code behind.