如何在ListView中设置附加的网格属性。

发布于 2025-01-30 18:33:25 字数 1461 浏览 2 评论 0原文

如何设置附加属性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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

恋你朝朝暮暮 2025-02-06 18:33:25

尽管网格来自面板,但并非被设计用作包装盒的项目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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文