我有自定義控件,它處理來自控件的事件並將其引發爲父項。MVVM事件和ICommand綁定
控制代碼
public delegate void ThumbMovedEventHandler(object sender);
public event ThumbMovedEventHandler ThumbMoved;
private void SliderTimeLine_OnDragCompleted(object sender, DragCompletedEventArgs e)
{
if (ThumbMoved != null)
ThumbMoved(this);
}
我想在我的MVVM應用程序中的事件的命令綁定。
查看代碼
<TimeTimeSlider:TimeSlider
StartDate="{Binding TimeLineStartDate}"
local:CommandBehavior.Event="ThumbMoved"
local:CommandBehavior.Action="{Binding ThumbMoved}"
local:CommandBehavior.CommandParameter="Thumb Place Ment Moved "
/>
視圖模型代碼
private ICommand thumbMoverCommand;
public ICommand ThumbMoved
{
get { return this.thumbMoverCommand ?? (this.thumbMoverCommand = new DelegateCommand(this.ExcuteThumbMoved)); }
}
public void ExcuteThumbMoved()
{
//Do Something;
}
事件時從控制扔到CommandBehaviorBinding
public ICommand Command
{
get { return _command; }
set
{
_command = value;
//set the execution strategy to execute the command
_strategy = new CommandExecutionStrategy { Behavior = this };
}
}
public void Execute()
{
_strategy.Execute(CommandParameter);
}
我得到一個「對象未設置稱爲類到一個對象的實例「錯誤,因爲_strategy爲空。
我該如何解決這個問題?
我沒有看到任何代碼將'_strategy'分配給任何東西。我看到*會分配給它的自定義設置存取器,但我沒有看到任何所謂的。 –