Silverlight 3 BETA DataGrid Group

NB it was for silverlight 3 beta, RTM seems to handle the grouping in a completely different way.

I have a grid that works fine, and I use the GroupDescriptions property as follows:

<data:DataGrid.GroupDescriptions>
    <cm:PropertyGroupDescription PropertyName="ClientName" />
</data:DataGrid.GroupDescriptions>

This works brilliantly, only when the datagrid rendering is displayed, it shows the grouping by "ClientName". Obviously, I would like it to be "Customer Name". For my life I cannot see a property that would allow me to establish this?

+3
source share
4 answers

FWIW this has changed in RTM RTM:

Silverlight 3 Beta p>

[Xaml]

<dataGrid.GroupDescriptions>

      <windata:PropertyGroupDescription PropertyName="State" />

</dataGrid.GroupDescriptions>

Silverlight 3 RTM

[FROM#]

pagedCollectionView.GroupDescriptions.Add(new PropertyGroupDescription("State"));

, PagedCollectionView, Xaml. . http://msdn.microsoft.com/en-us/library/dd833072(VS.95).aspx

, :

DataGrid, . DataGridRowGroupHeader, RowGroupHeaderStyles. , . , . , , . . DataContext DataGridRowGroupHeader CollectionViewGroup, .

, :

<dataControls:DataGrid x:Name="Grid">
    <dataControls:DataGrid.RowGroupHeaderStyles>
        <Style TargetType="dataControls:DataGridRowGroupHeader">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate>
                        <TextBlock Text="My text."/>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
   </dataControls:DataGrid.RowGroupHeaderStyles>
</dataControls:DataGrid>

, , , DataGridRowGroupHeader, . WPF, , "GroupText", 9 !

+8

, DaRKoN_, , . Blend, DataGridRowGroupHeader. :

<data:DataGrid>
  <data:DataGrid.RowGroupHeaderStyles>
    <Style TargetType="data:DataGridRowGroupHeader">
      <Setter Property="Template">
        <Setter.Value>
          <ControlTemplate TargetType="data:DataGridRowGroupHeader">
            <dataPrimitives:DataGridFrozenGrid x:Name="Root" Background="{TemplateBinding Background}">
              <dataPrimitives:DataGridFrozenGrid.Resources>
                <ControlTemplate x:Key="ToggleButtonTemplate" TargetType="ToggleButton">
                  <Grid Background="Transparent">
                    <VisualStateManager.VisualStateGroups>
                      <VisualStateGroup x:Name="CommonStates">
                        <VisualState x:Name="Normal"/>
                        <VisualState x:Name="MouseOver">
                          <Storyboard>
                            <ColorAnimation Duration="0" Storyboard.TargetName="CollapsedArrow" Storyboard.TargetProperty="(Stroke).Color" To="#FF6DBDD1"/>
                            <ColorAnimation Duration="0" Storyboard.TargetName="ExpandedArrow" Storyboard.TargetProperty="(Fill).Color" To="#FF6DBDD1"/>
                          </Storyboard>
                        </VisualState>
                        <VisualState x:Name="Pressed">
                          <Storyboard>
                            <ColorAnimation Duration="0" Storyboard.TargetName="CollapsedArrow" Storyboard.TargetProperty="(Stroke).Color" To="#FF6DBDD1"/>
                            <ColorAnimation Duration="0" Storyboard.TargetName="ExpandedArrow" Storyboard.TargetProperty="(Fill).Color" 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 x:Name="CollapsedArrow" Stretch="Uniform" Stroke="#FF414345" HorizontalAlignment="Center" VerticalAlignment="Center" Width="5" Visibility="Collapsed" Data="F1 M 0,0 L 0,1 L .6,.5 L 0,0 Z"/>
                    <Path x:Name="ExpandedArrow" Fill="#FF414345" Stretch="Uniform" HorizontalAlignment="Center" VerticalAlignment="Center" Width="6" Data="F1 M 0,1 L 1,1 L 1,0 L 0,1 Z"/>
                  </Grid>
                </ControlTemplate>
              </dataPrimitives:DataGridFrozenGrid.Resources>
              <dataPrimitives:DataGridFrozenGrid.ColumnDefinitions>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition/>
              </dataPrimitives:DataGridFrozenGrid.ColumnDefinitions>
              <VisualStateManager.VisualStateGroups>
                <VisualStateGroup x:Name="CurrentStates">
                  <VisualState x:Name="Regular"/>
                  <VisualState x:Name="Current">
                    <Storyboard>
                      <DoubleAnimation Duration="0" Storyboard.TargetName="FocusVisual" Storyboard.TargetProperty="Opacity" To="1"/>
                    </Storyboard>
                  </VisualState>
                </VisualStateGroup>
              </VisualStateManager.VisualStateGroups>
              <dataPrimitives:DataGridFrozenGrid.RowDefinitions>
                <RowDefinition Height="Auto"/>
                <RowDefinition/>
                <RowDefinition Height="Auto"/>
              </dataPrimitives:DataGridFrozenGrid.RowDefinitions>
              <Rectangle Fill="#FFFFFFFF" Height="1" Grid.Column="1" Grid.ColumnSpan="5"/>
              <Rectangle x:Name="IndentSpacer" Grid.Column="1" Grid.Row="1"/>
              <ToggleButton x:Name="ExpanderButton" Height="15" Margin="2,0,0,0" Width="15" Template="{StaticResource ToggleButtonTemplate}" Grid.Column="2" Grid.Row="1"/>
              <StackPanel Margin="0,1,0,1" VerticalAlignment="Center" Grid.Column="3" Grid.Row="1" Orientation="Horizontal">

                <TextBlock x:Name="PropertyNameElement" Margin="4,0,0,0" Visibility="{TemplateBinding PropertyNameVisibility}"/>

                <TextBlock Margin="4,0,0,0" Text="{Binding Name}"/>
                <TextBlock x:Name="ItemCountElement" Margin="4,0,0,0" Visibility="{TemplateBinding ItemCountVisibility}"/>
              </StackPanel>
              <Rectangle Fill="#FFD3D3D3" Height="1" Grid.Column="1" Grid.ColumnSpan="5" Grid.Row="2"/>
              <Rectangle x:Name="FocusVisual" Stroke="#FF6DBDD1" StrokeThickness="1" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" IsHitTestVisible="false" Opacity="0" Grid.Column="1" Grid.ColumnSpan="4" Grid.RowSpan="3"/>
              <dataPrimitives:DataGridRowHeader x:Name="RowHeader" Grid.RowSpan="3" dataPrimitives:DataGridFrozenGrid.IsFrozen="True"/>
            </dataPrimitives:DataGridFrozenGrid>
          </ControlTemplate>
        </Setter.Value>
      </Setter>
    </Style>
  </data:DataGrid.RowGroupHeaderStyles>
</data:DataGrid>

TextBlock, . , XAML:

<data:DataGrid>
   <data:DataGrid.RowGroupHeaderStyles>
     <Style TargetType="data:DataGridRowGroupHeader">
       <Setter Property="PropertyNameVisibility" Value="Collapsed"/>
     </Style>
  <data:DataGrid.RowGroupHeaderStyles>
</data:DataGrid>

, TextBlock Text:

<TextBlock Margin="4,0,0,0" Visibility="{TemplateBinding PropertyNameVisibility}" Text="Client Name:"/>

DataGridRowGroupHeader TextBlock PropertyNameElement , , .

+3

, Martin Liversage (!), . .. , . , , . Toby

!
. http://msdn.microsoft.com/en-us/library/cc278075(VS.95).aspx
DataGrid , :

<data:DataGrid.RowGroupHeaderStyles>
<Style TargetType="local: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="local:DataGridRowGroupHeader">
     ...snip...
     </ControlTemplate>
    </Setter.Value>
</Setter>
</Style>
</data:DataGrid.RowGroupHeaderStyles>  

Height .

0

Name Display, , :

[System.ComponentModel.DataAnnotations.Display( Name = "My Property" )]
public string MyProperty {get;set;}

looking at the Display class, you might think that the name GroupName will be your destination, but, alas, it is not.

I understand that a “muddy” model with displayed data is not always the way everyone (including me) likes to do something ... but unlike the amount of work needed for this in the above methods .. I think he will benefit from this time.

0
source

Source: https://habr.com/ru/post/1712266/


All Articles