我正在使用WrapPanel(具有垂直方向)作爲ItemsControl的項目面板。沒有添加組風格,項目可以正常變形。當我爲項目控件添加組風格時,wrappanel不會包裝項目,所有項目都會在單個列中垂直顯示,而不是跨越多個列。我沒有爲組頁眉或ItemTemplate使用任何複雜的佈局。WPF Group Style令人不安的包裝面板包裝
這裏是XAML源..
<Grid>
<ItemsControl ItemsSource="{Binding Items}" Grid.Row="0" ScrollViewer.VerticalScrollBarVisibility="Disabled" ScrollViewer.HorizontalScrollBarVisibility="Visible">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel Orientation="Vertical"
MaxHeight="{Binding RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type Grid}},Path=ActualHeight}"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.GroupStyle>
<GroupStyle>
<GroupStyle.HeaderTemplate>
<DataTemplate>
<StackPanel>
<TextBlock FontSize="15" FontWeight="Bold" Text="{Binding Name}"/>
</StackPanel>
</DataTemplate>
</GroupStyle.HeaderTemplate>
</GroupStyle>
</ItemsControl.GroupStyle>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"></ColumnDefinition>
<ColumnDefinition Width="*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<TextBlock Text="{Binding Name}"/>
<TextBox Text="{Binding Value}" Grid.Column="1" HorizontalAlignment="Right"></TextBox>
</Grid>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</Grid>
,這如何幫助? –
我正在使用wrappanel來封裝項目控件中的項目(請參閱我的問題中的ItemsControl.ItemsPanel部分。)。當我們使用組風格時,wpf將忽略項目控制面板並將使用組面板,因爲它需要實現組風格。所以在我的情況下,它忽略了我的wrappanle,並使用默認的panle作爲stackpanel的組風格 – Bathineni