2009-07-10 8 views
3

NBこれはシルバーライト3ベータ版で、RTMはグループ化を完全に異なるように扱っているようです。Silverlight 3ベータデータグリッドグループ

私はそうのようなGroupDescriptionsプロパティを使用しています正常に動作しているグリッドを、しました:

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

これは見事に動作しますが、それは「データグリッドが描画されている場合にのみ、それはによってグループ分けを示していますClientName "。明らかに、私はそれが「クライアント名」であることを望みます。私は私の人生は私がこれを設定することができるプロパティを参照してくださいすることはできません?

答えて

8

FWIWこのSL3 RTMに変更されました:

シルバー3ベータ

[XAML]

<dataGrid.GroupDescriptions> 

     <windata:PropertyGroupDescription PropertyName=”State” /> 

</dataGrid.GroupDescriptions> 

シルバー3 RTM

[C#の]

pagedCollectionView.GroupDescriptions.Add(new PropertyGroupDescription(“State”)); 

あなたはねdこれを達成するためにPagedCollectionViewクラスを使用するには、Xamlでこれを行うことはできません。 http://msdn.microsoft.com/en-us/library/dd833072(VS.95).aspx

そして、そのリンクからを参照してください、ここでグループヘッダー内のテキストを変更する方法は次のとおりです。

項目がデータグリッドにグループ化されている場合は、各グループは、ヘッダを持っています。 DataGridRowGroupHeaderの外観を変更するには、カスタムスタイルを定義し、それをRowGroupHeaderStylesコレクションに追加します。グループ化のレベルが複数ある場合は、各グループレベルに異なるスタイルを適用できます。スタイルは、定義された順序で適用されます。たとえば、2つのスタイルを定義すると、最初のスタイルが最上位の行グループに適用されます。第2のスタイルは、第2レベル以下のすべての行グループに適用されます。 DataGridRowGroupHeaderのDataContextは、ヘッダーが表す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ヤード全体を移動する必要があります。

+0

ページビューコレクションとは何ですか? CollectionViewSourceを使ってみましたが、GroupDescriptionsプロパティは実装されていません。 – ChadT

+0

申し訳ありませんが、不完全な答え - 投稿を更新しました。 –

3

DaRKoN_と同じ問題があり、James Caddの洞察力の高い答えを読んだことで、私は自分の問題を解決しました。 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の前後に空白行を追加している問題のテキストが含まれています。あなたが持っている両方のTextBlockの名前を削除し、Text属性を追加するテキストを変更したい場合は

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

:あなたは完全に、次のXAMLを使用して、それをオフにすることができ

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

DataGridRowGroupHeaderPropertyNameElementという名前のTextBlockが検索され、コードからテキストが設定されます。これを避けるには、テンプレートから名前を削除する必要があります。

0

Martin Liversage(感謝!)が提供してくれたテンプレートを実装しましたが、グループデータ行の高さを制御できないようです。長方形などのサイズを調整するだけで、行の中でより多くの部屋が占有され、他の部分が隠されます。行の高さは、テンプレートの影響を受けない行のコンテナによって制御されているようです。 TIA Toby

答えを見つけました!
http://msdn.microsoft.com/en-us/library/cc278075(VS.95).aspx
を参照してください。これは、すべてのコントロールのスタイルとテンプレートを定義し、データグリッドにズームし、あなたが見つける既定のテンプレートを表示する:Heightプロパティを設定する

<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> 

は仕事をしていません。表示属性のNameプロパティを設定し

+0

Blendを使用してテンプレートを抽出する方法を知りたいのですが... –

+0

Blendを使用してデフォルトのテンプレートを取得する方法を調べるのに約5分を費やしましたが、Reflectorを開いてアセンブリのリソースからgeneric.xamlを抽出しました。マイクロソフトは本当にこれのために、より良い解決策を考え出す必要があります。 – Rory

0

がによってあなたは、グループ化しているプロパティに適用:

Displayクラスを見て
[System.ComponentModel.DataAnnotations.Display(Name = "My Property")] 
public string MyProperty {get;set;} 

、一つはGroupNameのは、あなたが設定されたプロパティになると思いますが、それも悲しいかもしれませんない。

私はディスプレイデータでモデルを「泥だらけ」と理解していますが、皆さん(自分自身が含む)が物事を好きなようにはなりません。しかし、上記の方法でそれを行うのに必要な作業量とは対照的です。今度は勝つと思う。

関連する問題