我已經設置了MaximumRowsOrColumns = 「2」 在ItemsWrapGrid,它工作正常。請檢查我的代碼,看看你是否錯過了一些東西。 在MainPage.xaml:
<Page.Resources>
<CollectionViewSource x:Key="cvs" ItemsPath="showitem" x:Name="cvs" IsSourceGrouped="True"></CollectionViewSource>
</Page.Resources>
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<ListView Width="500" ItemsSource="{Binding Source={StaticResource cvs}}">
<ListView.ItemsPanel>
<ItemsPanelTemplate>
<ItemsWrapGrid MaximumRowsOrColumns="2" Orientation="Horizontal"></ItemsWrapGrid>
</ItemsPanelTemplate>
</ListView.ItemsPanel>
<ListView.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Path=Name}" />
<TextBox Width="50" BorderBrush="Blue" BorderThickness="3"></TextBox>
</StackPanel>
</DataTemplate>
</ListView.ItemTemplate>
<ListView.GroupStyle>
<GroupStyle>
<GroupStyle.HeaderTemplate>
<DataTemplate>
<StackPanel Width="400" Height="60" Background="Blue">
<TextBlock HorizontalAlignment="Center" VerticalAlignment="Center" Text="{Binding id}" Foreground="Red"></TextBlock>
</StackPanel>
</DataTemplate>
</GroupStyle.HeaderTemplate>
</GroupStyle>
</ListView.GroupStyle>
</ListView>
</Grid>
在MainPage.xaml.cs:
public class test
{
public string Name { get; set; }
}
public class testlist
{
public string id { get; set; }
public List<test> showitem { get; set; }
}
public sealed partial class MainPage : Page
{
public MainPage()
{
this.InitializeComponent();
List<testlist> mylist = new List<testlist>();
testlist testlist = new testlist();
testlist.id = "group1";
testlist.showitem = new List<test>();
testlist.showitem.Add(new test() { Name = "Test1" });
testlist.showitem.Add(new test() { Name = "Test2" });
mylist.Add(testlist);
testlist testlist1 = new testlist();
testlist1.id = "group1";
testlist1.showitem = new List<test>();
testlist1.showitem.Add(new test() { Name = "Test3" });
testlist1.showitem.Add(new test() { Name = "Test4" });
mylist.Add(testlist1);
this.cvs.Source = mylist;
}
}
結果:
它沒有工作了,它工作得很好,當有沒有分組。但是,當我分組的數據,然後它不工作 –
試試這個:http://stackoverflow.com/questions/33782294/uwp-grouped-gridview-with-wrapgrid你可以使用網格視圖,而不是一個列表視圖 – Jun