xaml - Detect mouse left button down (Click) outside a border WPF MVVM -
i have border in mvvm. trying achieve detect mouse left button down outside border , hide it. can within mouseleftbuttondown event main window, not know if best solution. how this? want avoid click interfere other events, example, border placed in stackpanel , stackpanel being hidden on mouse left button double click.
<border grid.row="2" x:name="custompopup" cornerradius="10,10,0,0" height="25" margin="0" horizontalalignment="center" verticalalignment="center" width="auto" borderbrush="darkblue" borderthickness="1" background="antiquewhite"> <stackpanel orientation="horizontal" horizontalalignment="center"> <image source="/common.images;component/images/info.png" height="20" width="20" stretch="fill"/> <textblock margin="5" verticalalignment="center" horizontalalignment="left" background="transparent" fontsize="12"> <run text="click outside close it"/> </textblock> </stackpanel> </border>
using mousedown
on window best bet desired results. you'll need calculations in order see if cursor outside of border. like:
private void window_mousedown(object sender, mousebuttoneventargs e) { // positions point mouseloc = mouse.getposition(null); point borderloc = custompopup.translatepoint(new point(0,0), null); // check if mouse outside border if((mouseloc.x < borderloc.x || mouseloc.x > (borderloc.x + custompopup.actualwidth)) && (mouseloc.y < borderloc.y || mouseloc.y > borderloc.y + custompopup.actualheight)) { // hide border } }
then handle double click, use previewmousedoubleclick
. since preview events tunneling rather bubbling, double click should called if have single click event on same element.
private void window_previewmousedoubleclick(object sender, mousebuttoneventargs e) { // double click code... e.handled = true; }
Comments
Post a Comment