bool을 매개 변수로 사용하여 PRISM delegatecommand를 사용하려고합니다. 내가 CanExecuteChangeZoomPan
에 중단 점을 설정DelegateCommand throw ""지정된 캐스트가 유효하지 않습니다 "
public class ChartViewModel : BindableBase
{
public DelegateCommand<bool?> ChangeZoomPanCommand { get; private set; }
private bool isInRealtimeMode;
public bool IsInRealtimeMode
{
get { return isInRealtimeMode; }
set
{
SetProperty(ref isInRealtimeMode, value);
ChangeZoomPanCommand.RaiseCanExecuteChanged();
}
}
private bool dragToZoom;
public bool DragToZoom
{
get { return dragToZoom; }
set { SetProperty(ref dragToZoom, value); }
}
public ChartViewModel()
{
ChangeZoomPanCommand = new DelegateCommand<bool?>(ExecuteChangeZoomPan, CanExecuteChangeZoomPan);
IsInRealtimeMode = true;
DragToZoom = true;
}
private bool CanExecuteChangeZoomPan(bool? arg)
{
return !IsInRealtimeMode;
}
private void ExecuteChangeZoomPan(bool? enableZoom)
{
if (enableZoom.HasValue)
{
DragToZoom = enableZoom.Value;
}
}
}
가 공격 결코 극복이는 관련 코드입니다. 문제는 ChangeZoomPanCommand.RaiseCanExecuteChanged()
이후에 발생합니다. 내가 문자열 모두에 대한 인수 유형이 작동하는 것 같다 변경하는 경우
>
at Prism.Commands.DelegateCommand`1.<>c__DisplayClass1_0.<.ctor>b__1(Object o)
at Prism.Commands.DelegateCommandBase.CanExecute(Object parameter)
at Prism.Commands.DelegateCommandBase.System.Windows.Input.ICommand.CanExecute(Object parameter)
at MS.Internal.Commands.CommandHelpers.CanExecuteCommandSource(ICommandSource commandSource)
at System.Windows.Controls.Primitives.ButtonBase.UpdateCanExecute()
at System.Windows.Controls.Primitives.ButtonBase.HookCommand(ICommand command)
at System.Windows.Controls.Primitives.ButtonBase.OnCommandChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
at System.Windows.DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
at System.Windows.FrameworkElement.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
at System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args)
at System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType)
at System.Windows.DependencyObject.InvalidateProperty(DependencyProperty dp, Boolean preserveCurrentValue)
at System.Windows.Data.BindingExpressionBase.Invalidate(Boolean isASubPropertyChange)
at System.Windows.Data.BindingExpression.TransferValue(Object newValue, Boolean isASubPropertyChange)
at System.Windows.Data.BindingExpression.Activate(Object item)
at System.Windows.Data.BindingExpression.AttachToContext(AttachAttempt attempt)
at System.Windows.Data.BindingExpression.MS.Internal.Data.IDataBindEngineClient.AttachToContext(Boolean lastChance)
at MS.Internal.Data.DataBindEngine.Task.Run(Boolean lastChance)
at MS.Internal.Data.DataBindEngine.Run(Object arg)
at MS.Internal.Data.DataBindEngine.OnLayoutUpdated(Object sender, EventArgs e)
at System.Windows.ContextLayoutManager.fireLayoutUpdateEvent()
at System.Windows.ContextLayoutManager.UpdateLayout()
at System.Windows.ContextLayoutManager.UpdateLayoutCallback(Object arg)
at System.Windows.Media.MediaContext.InvokeOnRenderCallback.DoWork()
at System.Windows.Media.MediaContext.FireInvokeOnRenderCallbacks()
at System.Windows.Media.MediaContext.RenderMessageHandlerCore(Object resizedCompositionTarget)
at System.Windows.Media.MediaContext.AnimatedRenderMessageHandler(Object resizedCompositionTarget)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
:
이
은 스택 트레이스입니다. 그런 다음 xaml 명령 매개 변수이므로 "거짓"문자열을 인수로 사용합니다. T가 아무런 제한도없는 것처럼 보이는 이유는 무엇인가 T와 관련이없는 이유는 무엇입니까? T가 객체이거나 Nullable이어야한다는 사실을 이미 알았지 만 Nullable도 적합하지 않은 것으로 나타났습니다. bool 인수로 작업하는 방법?감사
나는 그걸로 살 수 있고, 지금은 그 해결 방법이다. 그런데 왜 위의 문제가 나타 납니까? 명령은 호출되지 않고'RaiseCanExecuteChanged' 만 호출됩니다. 그냥'CanExecuteChangeZoomPan'을 호출하면 안됩니다. 일반적인 제약 조건을 사용하는 것이 좋을까요? –
'CanExecute'도 명령 매개 변수를 전달하므로 거기에서도 변환이 발생합니다. 나는 제약이 여기 어떤 것도 바꿀 것이라고 생각하지 않는다. –