将PropertyGroupDescription添加到PageCollectedView.GroupDescriptions时,我提供null作为属性名称和IValueConverter.我这样做,以便我可以对一组属性值进行单一分组. Howerver显示屏显示前导:在DataGrid中的分组值之前.
在另一种情况下,我通过单个属性进行分组,因此我提供了一个PropertyGroupDescription实例,其中包含属性名称而没有IValueConverter.在这种情况下,显示屏将显示属性名称冒号,然后显示分组值.
解决方法
使用这些代码希望您的问题得到解决.
<sdk:DataGrid.RowGroupHeaderStyles> <Style targettype="sdk:DataGridRowGroupHeader"> <Setter Property="Cursor" Value="Arrow" /> <Setter Property="IsTabStop" Value="False" /> <Setter Property="Background" Value="#FFE4E8EA" /> <Setter Property="Height" Value="20"/> <Setter Property="Template"> <Setter.Value> <ControlTemplate targettype="sdk:DataGridRowGroupHeader"> <sdk:DataGridFrozenGrid x:Name="Root" Background="{TemplateBinding Background}"> <sdk:DataGridFrozenGrid.Resources> <ControlTemplate x:Key="ToggleButtonTemplate" targettype="ToggleButton"> <Grid> <visualstatemanager.VisualStateGroups> <VisualStateGroup x:Name="CommonStates"> <VisualState x:Name="normal"/> <VisualState x:Name="MouSEOver"> <Storyboard> <ColorAnimation Storyboard.TargetName="CollapsedArrow" Storyboard.TargetProperty="(stroke).Color" Duration="0" To="#FF6DBDD1"/> <ColorAnimation Storyboard.TargetName="ExpandedArrow" Storyboard.TargetProperty="(Fill).Color" Duration="0" To="#FF6DBDD1"/> </Storyboard> </VisualState> <VisualState x:Name="pressed"> <Storyboard> <ColorAnimation Storyboard.TargetName="CollapsedArrow" Storyboard.TargetProperty="(stroke).Color" Duration="0" To="#FF6DBDD1"/> <ColorAnimation Storyboard.TargetName="ExpandedArrow" Storyboard.TargetProperty="(Fill).Color" Duration="0" To="#FF6DBDD1"/> </Storyboard> </VisualState> <VisualState x:Name="disabled"> <Storyboard> <DoubleAnimation Duration="0" Storyboard.TargetName="CollapsedArrow" Storyboard.TargetProperty="Opacity" To=".5"/> <DoubleAnimation Duration="0" Storyboard.TargetName="ExpandedArrow" Storyboard.TargetProperty="Opacity" To=".5"/> </Storyboard> </VisualState> </VisualStateGroup> <VisualStateGroup x:Name="CheckStates"> <VisualState x:Name="Checked" /> <VisualState x:Name="Unchecked"> <Storyboard> <ObjectAnimationUsingKeyFrames Duration="0" Storyboard.TargetName="CollapsedArrow" Storyboard.TargetProperty="Visibility"> <discreteObjectKeyFrame KeyTime="0" Value="Visible"/> </ObjectAnimationUsingKeyFrames> <ObjectAnimationUsingKeyFrames Duration="0" Storyboard.TargetName="ExpandedArrow" Storyboard.TargetProperty="Visibility"> <discreteObjectKeyFrame KeyTime="0" Value="Collapsed"/> </ObjectAnimationUsingKeyFrames> </Storyboard> </VisualState> </VisualStateGroup> </visualstatemanager.VisualStateGroups> <Path Stretch="Uniform" Data="F1 M 0,0 L 0,1 L .6,.5 L 0,0 Z" Width="5" HorizontalAlignment="Center" VerticalAlignment="Center" x:Name="CollapsedArrow" Visibility="Collapsed" stroke="#FF414345"/> <Path Stretch="Uniform" Data="F1 M 0,1 L 1,1 Z" Width="6" HorizontalAlignment="Center" VerticalAlignment="Center" x:Name="ExpandedArrow" Fill="#FF414345"/> </Grid> </ControlTemplate> </sdk:DataGridFrozenGrid.Resources> <visualstatemanager.VisualStateGroups> <VisualStateGroup x:Name="CurrentStates"> <VisualState x:Name="Regular"/> <VisualState x:Name="Current"> <Storyboard> <DoubleAnimation Storyboard.TargetName="FocusVisual" Storyboard.TargetProperty="Opacity" To="1" Duration="0" /> </Storyboard> </VisualState> </VisualStateGroup> </visualstatemanager.VisualStateGroups> <sdk:DataGridFrozenGrid.ColumnDeFinitions> <ColumnDeFinition Width="Auto" /> <ColumnDeFinition Width="Auto" /> <ColumnDeFinition Width="Auto" /> <ColumnDeFinition Width="Auto" /> <ColumnDeFinition/> </sdk:DataGridFrozenGrid.ColumnDeFinitions> <sdk:DataGridFrozenGrid.RowDeFinitions> <RowDeFinition Height="Auto"/> <RowDeFinition/> <RowDeFinition Height="Auto"/> </sdk:DataGridFrozenGrid.RowDeFinitions> <Rectangle Grid.Column="1" Grid.ColumnSpan="5" Fill="#FFFFFFFF" Height="1"/> <Rectangle Grid.Column="1" Grid.Row="1" x:Name="IndentSpacer" /> <ToggleButton Grid.Column="2" Grid.Row="1" x:Name="ExpanderButton" Height="15" Width="15" IsTabStop="False" Template="{StaticResource ToggleButtonTemplate}" Margin="2,0"/> <!-- This is START of the First Group Header of the DataGrid --> <!--<StackPanel Grid.Column="3" Grid.Row="1" Orientation="Horizontal" VerticalAlignment="Center" Margin="0,1,1" Visibility="{Binding Width,ElementName=IndentSpacer}"> <TextBlock Margin="4,0" Text="{Binding Name}" Foreground="Red"/> </StackPanel>--> <!-- This is END of the First Group Header of the DataGrid --> <!-- This is START of the Second Group Header of the DataGrid --> <Grid Grid.Column="3" Grid.Row="1" VerticalAlignment="Center" HorizontalAlignment="Stretch" Margin="0,1" Visibility="{Binding Width,ElementName=IndentSpacer}"> <StackPanel Orientation="Horizontal" HorizontalAlignment="Left"> <!--<ComboBox Margin="4,0" Width="120" ItemsSource="{Binding ItemsSource,ElementName=personDataGrid,Converter={StaticResource ConvToComboBox}}" displayMemberPath="text" SelectionChanged="comboSelectionChangeda"/> <Button Margin="169,0" Height="15" Name="btn" Content="+" FontSize="9" Foreground="Black" FontWeight="Bold" Click="btn_Click"/>--> <sdk:Label Content="{Binding ItemsSource,Converter={StaticResource ConvToGender}}"/> </StackPanel> </Grid> <!-- This is END of Second Group Header of the DataGrid --> <Rectangle Grid.Column="1" Grid.ColumnSpan="5" Fill="#FFD3D3D3" Height="1" Grid.Row="2"/> <Rectangle x:Name="FocusVisual" Grid.Column="1" Grid.ColumnSpan="4" Grid.RowSpan="3" stroke="#FF6DBDD1" strokeThickness="1" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" IsHitTestVisible="false" Opacity="0" /> <sdk:DataGridRowHeader x:Name="RowHeader" Grid.RowSpan="3" sdk:DataGridFrozenGrid.IsFrozen="True"/> </sdk:DataGridFrozenGrid> </ControlTemplate> </Setter.Value> </Setter> </Style> </sdk:DataGrid.RowGroupHeaderStyles>
这是返回自定义组头的Converter类
公共类GenderConv:IValueConverter
{
public object Convert(object value,Type targettype,object parameter,System.Globalization.CultureInfo culture) { PagedCollectionView pageView = value as PagedCollectionView; Person person = pageView.CurrentItem as Person; string gender = person.Gender.ToString(); return "Sex:"+ gender; } public object ConvertBack(object value,System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } }
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。