When I right-click outside the area containing the slots,for example, on the header, the context menu that I have defined still appears provided that I have a selected slot or appointment. Is it possible to constrain the context menu to the slot area?
4 Answers, 1 is accepted
0
Hi Claire,
In order to achieve the desired behavior of RadContextMenu you need to handle the Opening event. Inside it you need to check if the clicked UIElement is a RadTransitionControl - the Slots and Appointments are placed inside such RadTransitionColtrol. If so, the Handled property should be set to True and thus the ContextMenu wont'be visualized:
Please, give a try to the proposed above approach and let us know if it worked for you.
Hope this helps.
Regards,
Nasko
Telerik
In order to achieve the desired behavior of RadContextMenu you need to handle the Opening event. Inside it you need to check if the clicked UIElement is a RadTransitionControl - the Slots and Appointments are placed inside such RadTransitionColtrol. If so, the Handled property should be set to True and thus the ContextMenu wont'be visualized:
private
void
RadContextMenu_Opening(
object
sender, Telerik.Windows.RadRoutedEventArgs e)
{
var slot = (sender
as
RadContextMenu).GetClickedElement<RadTransitionControl>();
if
(slot ==
null
)
{
e.Handled =
true
;
}
}
Please, give a try to the proposed above approach and let us know if it worked for you.
Hope this helps.
Regards,
Nasko
Telerik
Do you want to have your say when we set our development plans?
Do you want to know when a feature you care about is added or when a bug fixed?
Explore the
Telerik Feedback Portal
and vote to affect the priority of the items
0
Claire
Top achievements
Rank 1
answered on 09 Nov 2015, 04:39 PM
That's definitely much better.
The context menu still appears, however, if I right-click on a resource header, the week day header for example.
0
Accepted
Hello Claire,
The observed behavior is an expected one as RadTransitionControl contains the GroupHeaders as well. So, in order to restrict the Contextmenu from appearing even when the GroupHeader gets clicked you could use the following implementation:
You might still need to improve the logic if you want to prevent the ContextMenu from appearing when other UI elements get clicked - the approach is the same to use the GetClickedElement and based on it and its children to show the ContextMenu.
We hope this will help you.
Regards,
Nasko
Telerik
The observed behavior is an expected one as RadTransitionControl contains the GroupHeaders as well. So, in order to restrict the Contextmenu from appearing even when the GroupHeader gets clicked you could use the following implementation:
private
void
RadContextMenu_Opening(
object
sender, Telerik.Windows.RadRoutedEventArgs e)
{
var slot = (sender
as
RadContextMenu).GetClickedElement<Grid>();
if
(slot.Parent !=
null
)
{
if
(!(slot !=
null
&& slot.Parent.GetType() ==
typeof
(RadTransitionControl)))
{
e.Handled =
true
;
}
}
else
{
e.Handled =
true
;
}
}
You might still need to improve the logic if you want to prevent the ContextMenu from appearing when other UI elements get clicked - the approach is the same to use the GetClickedElement and based on it and its children to show the ContextMenu.
We hope this will help you.
Regards,
Nasko
Telerik
Do you want to have your say when we set our development plans?
Do you want to know when a feature you care about is added or when a bug fixed?
Explore the
Telerik Feedback Portal
and vote to affect the priority of the items
0
Claire
Top achievements
Rank 1
answered on 12 Nov 2015, 03:19 PM
Your proposed solution did prevent the context menu from popping up when right-clicking on a resource header, but also when right-clicking on an appointment, which is not desirable.
So I rewrote it as follows:
private
void
RadContextMenu_Opening(
object
sender, Telerik.Windows.RadRoutedEventArgs e)
{
var app = (sender
as
RadContextMenu).GetClickedElement<AppointmentItem>();
if
(app !=
null
)
{
return
;
}
var slot = (sender
as
RadContextMenu).GetClickedElement<Grid>();
if
(slot ==
null
|| slot.Parent ==
null
)
{
e.Handled =
true
;
return
;
}
if
(!(slot.Parent.GetType() ==
typeof
(RadTransitionControl)))
{
e.Handled =
true
;
}
}
This way, the context menu will appear only when the user right-click on a slot, not matter whether the slot is empty or not.