silverlight – 如何将分组标题从属性名称更改为更具描述性的名称

将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();
    }
}

相关文章

如何在Silverlight4(XAML)中绑定IsEnabled属性?我试过简单的...
我正在编写我的第一个vb.net应用程序(但我也会在这里标记c#,...
ProcessFile()是在UIThread上运行还是在单独的线程上运行.如...
我从同行那里听说,对sharepoint的了解对职业生涯有益.我们不...
我正在尝试保存一个类我的类对象的集合.我收到一个错误说明:...
我需要根据Silverlight中的某些配置值设置给定控件的Style.我...