MATLAB: WindowButtonDownFcn conflicting with ButtonDownFcn

buttondownfcncallbackguiwindowbuttondownfcn

What I want to achieve is this:
user clicks on an axes: -Run CallbackA
user clicks somewhere else in the figure: -Run CallbackB
What I have done is to set the ButtonDownFcn (CallbackA) of axes, and the WindowButtonDownFcn (CallbackB) of the figure.
Now the thing is that whenever I click on an axes, it runs both Callbacks (both WindowButtonDownFcn and ButtonDownFcn are triggered).
Can I avoid this, and trigger only one of them?

Best Answer

You can insert an axes object spanning this whole figure as a background and use its ButtonDownFcn:
BGcolor = get(0, 'DefaultFigureColor');
BGaxes = axes('Units', 'normalized', 'Position', [0,0,1,1], ...
'XTicks, [], 'YTicks', [], ...
'Color', BGcolor, 'XColor', BGcolor, 'YColor', BGcolor, ...
'ButtonDownFcn', 'disp(''Background'')');
DataAxes = axes('ButtonDownFcn', 'disp(''Data'')';