0

カスタム コントロールがあり、コントロールからのイベントを処理し、それを親にスローします。

制御コード

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 "
                                   />

ViewModel コード

    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 が null であるため、「オブジェクト参照がオブジェクトのインスタンスに設定されていません」というエラーが表示されます。

これを修正するにはどうすればよいですか?

4

2 に答える 2

0

local:CommandBehavior. Command ="{Binding ThumbMoved}"

     <TimeTimeSlider:TimeSlider 
               StartDate="{Binding TimeLineStartDate}"
               local:CommandBehavior.Event="ThumbMoved"
               local:CommandBehavior.Command="{Binding ThumbMoved}"
               local:CommandBehavior.CommandParameter="Thumb Place Ment Moved "
                               /> 
于 2013-09-22T09:58:02.120 に答える