Questions about MenuItem
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
cpp
Is it specification?
Those events is not occurred in WPF.
I think there is an issue when like below codes.
xaml
Code: Select all
<Grid MouseDown="Parent_MouseDown" MouseUp="Parent_MouseUp">
<Grid MouseDown="Child_MouseDown"">
<Grid.ContextMenu>
<ContextMenu>
<MenuItem Header="Item_1" Command="{Binding OnSelected_1}"/>
</ContextMenu>
...
Code: Select all
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!!
}
-
sfernandez
Site Admin
- Posts: 2983
- Joined:
Re: Questions about MenuItem
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.
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.
Re: Questions about MenuItem
The sample corresponding to that tutorial is included in the C++ SDK and is also available in GitHub
Re: Questions about MenuItem
Sorry, my xaml has been wrong.
I verified that menu item command is called.
I verified that menu item command is called.
Re: Questions about MenuItem
But, MouseDown/Up events come to owner control when click to context menu.
For example,
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?
For example,
Code: Select all
<Grid MouseDown="ChangeBackgroundColor">
<Grid.ContextMenu>
<ContextMenu>
<MenuItem Header="Item_1" Command="{Binding OnSelected}"/>
</ContextMenu>
...
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?
-
sfernandez
Site Admin
- Posts: 2983
- Joined:
Re: Questions about MenuItem
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?
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?
Re: Questions about MenuItem
I reported this bug to bugtracker.
Thank you in advance.
Thank you in advance.
Re: Questions about MenuItem
Thanks!