gpt4 book ai didi

c# - 具有相同View的ListView

转载 作者:太空宇宙 更新时间:2023-11-03 13:55:21 25 4
gpt4 key购买 nike

我有一些 ListView,我希望它们都具有相同的 View。所以,如果以下是我的 View:

<ListView.View>
<GridView>
<GridViewColumn Width="140" Header="Game Name"
DisplayMemberBinding="{Binding GameName}" />
<GridViewColumn Width="140" Header="Creator"
DisplayMemberBinding="{Binding Creator}" />
<GridViewColumn Width="140" Header="Publisher"
DisplayMemberBinding="{Binding Publisher}" />
</GridView>
</ListView.View>

我想要这样的东西:

<Grid>

<ListView>
<!--Here my ListView is the same defined above-->
</ListView>

<ListView>
<!--Here my ListView is the same defined above-->
</ListView>

</Grid>

我怎样才能做到这一点?

最佳答案

在资源中定义 View (在顶级控件的资源字典中,或在外部资源字典中):

<StackPanel>
<StackPanel.Resources>
<GridView x:Key="myView" x:Shared="false">
<GridViewColumn Width="140" Header="Game Name"
DisplayMemberBinding="{Binding GameName}" />
<GridViewColumn Width="140" Header="Creator"
DisplayMemberBinding="{Binding Creator}" />
<GridViewColumn Width="140" Header="Publisher"
DisplayMemberBinding="{Binding Publisher}" />
</GridView>
</StackPanel.Resources>

<ListView View="{StaticResource myView}"/>
<ListView View="{StaticResource myView}"/>
</StackPanel>

关于c# - 具有相同View的ListView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12429878/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com