开发者

wpf binding contextmenu

开发者 https://www.devze.com 2023-01-23 20:29 出处:网络
in my main view, I have a slider that can be used to scale the application. <Slider x:Name=\"zoomSlider\" VerticalAlignment=\"Center\" Value=\"1\" IsSnapToTickEnabled=\"True\" TickFrequency=开发者

in my main view, I have a slider that can be used to scale the application.

<Slider x:Name="zoomSlider" VerticalAlignment="Center" Value="1" IsSnapToTickEnabled="True" TickFrequency=开发者_如何学运维"0.2" TickPlacement="Both" Minimum="0.5" Maximum="3" SmallChange="0.5" LargeChange="0.5" Width="100" />

and every control is scale-transformed accordingly:

<Controls:AutoHidePanel AutoHide="False" AutoFade="True" Height="50" Orientation="Horizontal">
            <Controls:AutoHidePanel.LayoutTransform>
                <ScaleTransform
                ScaleX="{Binding Value, ElementName=zoomSlider}"
                ScaleY="{Binding Value, ElementName=zoomSlider}"/>
            </Controls:AutoHidePanel.LayoutTransform>
            <MenuControl />
        </Controls:AutoHidePanel>

This works fine: like this every control in my windows scales fine.

Now, the MenuControl is a view that has a splitbutton, and this splitbutton uses a context menu to display sub items. The button itself scales too, but the context menu does not scale.

How can I make sure that this context menu scales together with its button control?


Meanwhile I found a solution. I just set the data context of the context menu to its parent data context like:

<ContextMenu DataContext="{Binding RelativeSource={RelativeSource Mode=Self}, Path=PlacementTarget.DataContext}">
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号