2012-07-12 180 views
3

有誰知道如何將一個ContextMenu添加到GridView中的每一行?下面的例子工作,但增加了整個控件的contextmenu,也在空白空間,滾動條,標題等。感謝您的任何幫助。WPF Gridview上下文菜單

<GridView ContextMenu="{StaticResource DisplayedContextMenu}" ItemsSource="{Binding Data}" > 
    <GridView.View> 
     <GridView> 
     <GridViewColumn Header="Position" Width="0" DisplayMemberBinding="{Binding Position}" /> 
... 

回答

1
 <DataGrid Name="grid"> 
      <DataGrid.Resources> 
       <Style TargetType="DataGridRow"> 
        <Setter Property="ContextMenu"> 
         <Setter.Value> 
          <ContextMenu> 
           <MenuItem Header="Copy Row" /> 
           <MenuItem Header="Paste Row" /> 
          </ContextMenu> 
         </Setter.Value> 
        </Setter> 
       </Style> 
      </DataGrid.Resources> 
      <DataGrid.ContextMenu> 
       <ContextMenu> 
        <MenuItem Header="Copy Grid" /> 
        <MenuItem Header="Paste Grid" /> 
       </ContextMenu> 
      </DataGrid.ContextMenu> 
     </DataGrid> 

在ListView控件的情況下,你應該重寫樣式的ListViewItem等