Helmut P. Helmut P. - 8 months ago 72
C# Question

ScaleTransform scales ContextMenu partially

I got an application, where the whole window is scaling if a user resizes the window. This is the code to do this:

ContentDesktop.LayoutTransform = new ScaleTransform(scale, scale);

Now I needed a Button with a ContextMenu, and this menu should scale like the application window. To do this, I bound the RenderTransform of the ContextMenu to the ScaleTransform of the Button:

<ScaleTransform ScaleX="{Binding ScaleFactor}" ScaleY="{Binding ScaleFactor}"/>
<ContextMenu RenderTransform="{Binding RelativeSource={RelativeSource Self}, Path=PlacementTarget.RenderTransform}">
<MenuItem Header="Item 1"/>
<MenuItem Header="Item 2 wwww aaaa ssss iiii"/>

The text of the MenuItems is now scaling, but for bigger ScaleFactors (>1.2) only a part of the ContextMenu is shown. The right and the bottom part are missing. As if someone cut it of.
But when I check the size (width, height), the ContextMenu is bigger as painted.

Someone got an idea what this could be?



<ContextMenu LayoutTransform="{Binding ...}">

LayoutTransform: A transform that's applied before the layout pass. So the FrameworkElement gets rearranged in the greater scheme.

RenderTransform: A transform that's applied after the layout pass is completed. The ContextMenu spawns a new Window, but it's boundaries remain from before the transform and cut off the visual.