MVVM 패턴이있는 .Net 4.0 DataGrid를 사용하고 있습니다. 사용자가 셀을 선택하고 선택한 셀의 정보를 다른 DataGrid 행 (키보드 단축키 또는 컨텍스트 메뉴 복사/붙여 넣기를 통해)에 복사 할 수있게해야합니다. SelectedItem을 통해 이것을 얻으려고했거나 SelectedItem을 CommandParameter로 보내려고했지만이 기능은 셀 전체가 아닌 전체 행에서만 작동합니다. (DataGrid는 Float 필드가있는 객체가 포함 된 ObservableCollection에 바인딩됩니다.이 필드는 DataGrid 셀에 매핑됩니다.) WPF MVVM에서 DataGrid 셀을 한 행에서 다른 행으로 복사하는 방법이 있습니까? 사전 XAML에서 감사 :선택한 셀의 MVVM DataGrid 정보 복사
<DataGrid Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="9" AutoGenerateColumns="False" Height="Auto" HorizontalAlignment="Left"
Name="dataGrid" VerticalAlignment="Top" Width="{Binding ElementName=grid4,Path=Width}"
ScrollViewer.CanContentScroll="False" FrozenColumnCount="1" SelectionUnit="Cell" SelectionMode="Extended" CanUserSortColumns = "False"
CanUserReorderColumns="False" CanUserResizeRows="False" RowHeight="25" RowBackground="LightGray" AlternatingRowBackground="White"
ScrollViewer.VerticalScrollBarVisibility="Visible" ScrollViewer.HorizontalScrollBarVisibility="Visible"
ItemsSource="{Binding Layers, Mode=TwoWay}" SelectedItem="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=DataContext.Selection, Mode=TwoWay}">
<DataGrid.InputBindings>
<KeyBinding Gesture="Shift" Command="{Binding ItemHandler}" CommandParameter="{Binding ElementName=dataGrid, Path=SelectedItems}"></KeyBinding>
</DataGrid.InputBindings>
뷰 모델 :
private float _selection = 0.0f;
public float Selection
{
get
{
return _selection;
}
set
{
if (_selection != value)
{
_selection = value;
NotifyPropertyChanged("Selection");
}
}
}
...
public DelegateCommand<IList> SelectionChangedCommand = new DelegateCommand<IList>(
items =>
{
if (items == null)
{
NumberOfItemsSelected = 0;
return;
}
NumberOfItemsSelected = items.Count;
});
public ICommand ItemHandler
{
get
{
return SelectionChangedCommand;
}
}