Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
290
Change width of submenu dropdown at runtime?
posted

Is there anyway to setup the width of the submenu dropdown to be set automatically to the width of the screen?

Right now, it appears that the width gets set based on the number of items.

TIA.

  • 7922
    Verified Answer
    posted

    Hi

    There is not property in the menu which sets the width of the submenu dropdown. But you can do this using ControlTemplate of the menu and little code behind.

    First you have extract the MenuItem ControlTemplate using Blend.

    I have attached a sample with extracted ControlTemplate.

     

    Second Write converter that returns the plugin’s width

    public class WidthToScreen : IValueConverter

        {

            public object Convert(object value, Type targetType, object parameter, CultureInfo culture)

            {

                return Application.Current.Host.Content.ActualWidth;

            }

        }

     

    Third Bind the popup child width to menu item with using converter.

    <Border x:Name="PopupBorder" Width="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Width, Converter={StaticResource MyConverter}}" />

    This is the points how to resolve your issue.

    I have attached files that do this functionality.

     

    Hope this help.

    XamWebMenuTestApp.rar