WPF LOB 응용 프로그램 및 프리즘 사용 및 뷰 모델에서 UI를 구분하는 명령을 위임하고 있습니다.WPF MVVM 응용 프로그램에서 DataGridCellEditEventArgs를 전달하는 방법
사용자가보기 모델이나 서비스가 아닌 특정 셀에서 UI를 변경하면 다른 기능을 호출해야합니다.
나는 첨부 행동
public static class DataGridCellEditEndingBehaviour
{
private static readonly DependencyProperty CellEditEndingProperty
= DependencyProperty.RegisterAttached(
"CellEditEnding",
typeof(CellEditEnding),
typeof(DataGridCellEditEndingBehaviour),
null);
public static readonly DependencyProperty CommandProperty
= DependencyProperty.RegisterAttached(
"Command",
typeof(ICommand),
typeof(DataGridCellEditEndingBehaviour),
new PropertyMetadata(OnSetCommandCallback));
public static readonly DependencyProperty CommandParameterProperty
= DependencyProperty.RegisterAttached(
"CommandParameter",
typeof(object),
typeof(DataGridCellEditEndingBehaviour),
new PropertyMetadata(OnSetCommandParameterCallback));
public static ICommand GetCommand(DataGrid control)
{
return control.GetValue(CommandProperty) as ICommand;
}
public static void SetCommand(DataGrid control, ICommand command)
{
control.SetValue(CommandProperty, command);
}
public static void SetCommandParameter(DataGrid control, object parameter)
{
control.SetValue(CommandParameterProperty, parameter);
}
public static object GetCommandParameter(DataGrid control)
{
return control.GetValue(CommandParameterProperty);
}
private static void OnSetCommandCallback
(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs e)
{
DataGrid control = dependencyObject as DataGrid;
if (control != null)
{
CellEditEnding behavior = GetOrCreateBehavior(control);
behavior.Command = e.NewValue as ICommand;
}
}
private static void OnSetCommandParameterCallback
(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs e)
{
DataGrid control = dependencyObject as DataGrid;
if (control != null)
{
CellEditEnding behavior = GetOrCreateBehavior(control);
behavior.CommandParameter = e.NewValue;
}
}
private static CellEditEnding GetOrCreateBehavior(DataGrid control)
{
CellEditEnding behavior =
control.GetValue(CellEditEndingProperty) as CellEditEnding;
if (behavior == null)
{
behavior = new CellEditEnding(control);
control.SetValue(CellEditEndingProperty, behavior);
}
return behavior;
}
}
public class CellEditEnding : CommandBehaviorBase<DataGrid>
{
public CellEditEnding(DataGrid control)
: base(control)
{
control.CellEditEnding += OnCellEditEnding;
}
private void OnCellEditEnding(object sender, DataGridCellEditEndingEventArgs e)
{
ExecuteCommand();
}
}
을 만들었습니다 그리고
local:DataGridCellEditEndingBehaviour.Command ="{Binding CellChangedCommand}"
이벤트가 호출됩니다
, 나는 어떠한있는 EventArgs를하지 않는 사용하여 동일한을 호출 할 수 있어요 VM에서 내 delegateCommand, 어떻게 이벤트 인수를 검색 할 수 있습니까, 내가 명령 매개 변수를 통해 그것을 설정할 수 있습니까? 그렇다면 어떻게하면 위임 명령에 이벤트 인수를 전달할 수 있습니까?
CellEditEndigEvent가 진행되는 동안 값이 아직 VM에 아직 저장되어 있지 않으므로 처리기에서 강제로 값을 읽을 수있는 방법이 있으므로 값을 읽을 필요가 없습니다. CellEditEndingEventArgs 대신 VM에서 직접 읽을 수 있습니까?