WPF Image Control with Click Event

后端 未结 5 1561
天涯浪人
天涯浪人 2020-12-08 06:46

I wish to use an in my WPF Application which responds to mouse clicks. Only the \'Mouse Up\' and \'Moue Down\' events are available out of the box

5条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-08 07:38

    You can use a set of 4 handlers and 2 boolean variables:

    booleans:

    1. IsClicked
    2. IsEntered

    handlers:

    1. OnMouseDown- sets IsClicked true;
    2. OnMouseEnter- sets IsEntered true;
    3. OnMouseLeave - sets IsEntered false;
    4. OnMouseUp - if (IsClicked && IsEntered){ /TODO your logic/} and then sets IsClicked false;

    This construction implements the functionality of the classic click.

提交回复
热议问题