2012-01-06 18 views
2

通常、行をクリックすると行の詳細が表示されます。これを無効にして、DataGrid行をクリックするだけで行の詳細を表示するようにします。ユーザーが行ヘッダーをクリックすると、行の詳細が表示されます。どうすればいい?行が1をクリックしたときに説明を取得するために誰かを停止するには行ヘッダーをクリックしてDataGrid行の詳細を表示しますか?

答えて

2

がグリッドにこの属性を追加します。

<DataGrid Name="dgPrimary" RowDetailsVisibilityMode="Collapsed"> 

その後1は、発現ブレンドを使用することが最も簡単なの一つであり、型ChangePropertyActionの2つの動作を追加します。

  1. マウスアクション入る
    Properties Window in Blend for Mouse Enter

  2. ここ Properties Window in Blend for Mouse Leave


    は、ヘッダーの上にマウスを移動する前の元のデータグリッドであるマウスの休暇アクション

    enter image description here



テストプロジェクトのDataGrid dgPrimaryの上にマウスを移動したときです。すべての行の説明がどのように開いているかを確認します。ここで Result datagrid when mouse moves over it


は、DataGrid

dgPrimary.ItemsSource = Directory.GetFiles(@"C:\") 
            .Select((nm, index) => new 
            { 
             Original = System.IO.Path.GetFileName(nm), 
             New = string.Format("{0}_{1}{2}", System.IO.Path.GetFileNameWithoutExtension(nm), index, System.IO.Path.GetExtension(nm)) 
            }); 
にロードするためにデータグリッド

<DataGrid x:Name="dgPrimary" RowDetailsVisibilityMode="Collapsed"> 
    <DataGrid.RowDetailsTemplate> 
     <DataTemplate> 
      <StackPanel Margin="20,0,0,0" Orientation="Horizontal"> 
       <TextBlock FontWeight="Bold" Text="{Binding New}" /> 

      </StackPanel> 
     </DataTemplate> 
    </DataGrid.RowDetailsTemplate> 
    <DataGrid.Columns> 
     <DataGridTextColumn Binding="{Binding Original}" 
          Header="File Name Before" 
          IsReadOnly="True" /> 
     <DataGridTextColumn Binding="{Binding New}" 
          Header="File Name After" 
          IsReadOnly="True" /> 
    </DataGrid.Columns> 
    <i:Interaction.Triggers> 
     <i:EventTrigger EventName="MouseEnter"> 
      <ei:ChangePropertyAction PropertyName="RowDetailsVisibilityMode"> 
       <ei:ChangePropertyAction.Value> 
        <DataGridRowDetailsVisibilityMode>Visible</DataGridRowDetailsVisibilityMode> 
       </ei:ChangePropertyAction.Value> 
      </ei:ChangePropertyAction> 
     </i:EventTrigger> 
     <i:EventTrigger EventName="MouseLeave"> 
      <ei:ChangePropertyAction x:Name="cpaLeave" PropertyName="RowDetailsVisibilityMode"/> 
     </i:EventTrigger> 
    </i:Interaction.Triggers> 
</DataGrid> 

そして、背後にあるコードにブレンドからのタックコードです

関連する問題