tkawa
Topic Author
Posts: 18
Joined: 07 Nov 2018, 05:34

Questions about MenuItem

07 Nov 2018, 06:49

MouseDown/Up events come to owner control when click to context menu.
Is it specification?
Those events is not occurred in WPF.

I think there is an issue when like below codes.

xaml
<Grid MouseDown="Parent_MouseDown" MouseUp="Parent_MouseUp">
  <Grid MouseDown="Child_MouseDown"">
            <Grid.ContextMenu>
                <ContextMenu>
                    <MenuItem Header="Item_1" Command="{Binding OnSelected_1}"/>
                </ContextMenu>
                ...
cpp
        void Child_MouseDown(BaseComponent* sender, const MouseButtonEventArgs & e) {
          	// Call when push mouse button on context menu
        }
        
        void Parent_MouseDown(BaseComponent* sender, const MouseButtonEventArgs & e) {
          	// Call when push mouse button on context menu
          	MouseCapture();
        }
        
        void Parent_MouseUp(BaseComponent* sender, const MouseButtonEventArgs & e) {
          	// Call when release mouse button if after Parent_MouseDown is called
                ReleaseMouseCapture();
        }
        
        void OnSelected_1(BaseComponent* sender, const RoutedEventArgs & e) {
        	// Doesn't called!!
        }
 
User avatar
sfernandez
Site Admin
Posts: 2983
Joined: 22 Dec 2011, 19:20

Re: Questions about MenuItem

09 Nov 2018, 01:46

Hi,

There is something wrong with your xaml, MenuItem.Command property expects an ICommand object to be set, and you tried to bind to a function.
If you read the Commands tutorial you will see how to create a DelegateCommand in your ViewModel or code-behind to call a function, and how to define a property to expose that command.

Let me know if you face any more problems trying to implement it.

Regards.
 
User avatar
jsantos
Site Admin
Posts: 3905
Joined: 20 Jan 2012, 17:18
Contact:

Re: Questions about MenuItem

09 Nov 2018, 02:10

The sample corresponding to that tutorial is included in the C++ SDK and is also available in GitHub
 
tkawa
Topic Author
Posts: 18
Joined: 07 Nov 2018, 05:34

Re: Questions about MenuItem

13 Nov 2018, 06:45

Sorry, my xaml has been wrong.
I verified that menu item command is called.
 
tkawa
Topic Author
Posts: 18
Joined: 07 Nov 2018, 05:34

Re: Questions about MenuItem

13 Nov 2018, 06:48

But, MouseDown/Up events come to owner control when click to context menu.
For example,
<Grid MouseDown="ChangeBackgroundColor">
  <Grid.ContextMenu>
    <ContextMenu>
      <MenuItem Header="Item_1" Command="{Binding OnSelected}"/>
    </ContextMenu>
    ...
When it click menu item "Item_1",
WPF: OnSelected is called.
NoesisGUI: ChangeBackgroundColor and OnSelected are called.

Case this example, background color is changed when menu item is clicked.
Is it specification?
 
User avatar
sfernandez
Site Admin
Posts: 2983
Joined: 22 Dec 2011, 19:20

Re: Questions about MenuItem

14 Nov 2018, 12:28

You are right, MouseDown shouldn't be raised on the parent Grid, as MenuItem is handling the event when clicked.
This is related with a problem we recently found on how MouseDown, MouseLeftButtonDown and similar are raised in the UI element tree.
Could you please report it in our bugtracker so we can keep track of the issue and notify you when it is fixed?
 
tkawa
Topic Author
Posts: 18
Joined: 07 Nov 2018, 05:34

Re: Questions about MenuItem

26 Nov 2018, 03:11

I reported this bug to bugtracker.
Thank you in advance.
 
User avatar
jsantos
Site Admin
Posts: 3905
Joined: 20 Jan 2012, 17:18
Contact:

Re: Questions about MenuItem

27 Nov 2018, 11:50

Thanks!

Who is online

Users browsing this forum: Bing [Bot], Google [Bot], vinick and 64 guests