This question is locked. New answers and comments are not allowed.
Hello,
Ran across the following problem:
When using absolute Placement of a ContextMenu attached to a element in a UserControl that has a scale transform applied to it, the MousePosition reported in the Opening Event is not correct. It needs to be both Transformed to visual AND Scaled to produce the correct Absolute coordinates.
I understand the Transform to visual necessity, but it is my feeling that the Scaling step should not be necessary and should be considered a bug.
Here is my work-around:
The GetTransform is a extension function in my utilities:
Hope this saves someone a bit of time.
Scott
Ran across the following problem:
When using absolute Placement of a ContextMenu attached to a element in a UserControl that has a scale transform applied to it, the MousePosition reported in the Opening Event is not correct. It needs to be both Transformed to visual AND Scaled to produce the correct Absolute coordinates.
I understand the Transform to visual necessity, but it is my feeling that the Scaling step should not be necessary and should be considered a bug.
Here is my work-around:
var menu = (RadContextMenu) sender;
var ui= menu.UIElement;
var tf = App.TheCentralPage.GetTransform<ScaleTransform>();
var mp = ui.TransformToVisual(Application.Current.RootVisual).Transform(menu.MousePosition);
var mpf =
new
Point(mp.X * tf.ScaleX, mp.Y * tf.ScaleY);
menu.PlacementRectangle =
new
Rect(mpf.X, mpf.Y, 1, 1);
The GetTransform is a extension function in my utilities:
public
static
TransformType GetTransform<TransformType> (
this
FrameworkElement Element)
where TransformType : Transform
{
var transform = Element.GetValue(FrameworkElement.RenderTransformProperty)
as
TransformType;
if
(transform !=
null
)
return
transform;
var group = Element.GetValue(FrameworkElement.RenderTransformProperty)
as
TransformGroup;
if
(group !=
null
)
{
foreach
(var item
in
group.Children)
{
transform = item
as
TransformType;
if
(transform !=
null
)
return
transform;
}
}
return
null
;
}
Hope this saves someone a bit of time.
Scott