dropdown menu doesn't close after clicking

5 posts, 0 answers
  1. Andy
    Andy avatar
    13 posts
    Member since:
    Apr 2014

    Posted 21 Jul 2014 Link to this post

    Hi I am using RadMenu. I want the dropdown menu to close after one of the menuitems clicked.
    I am using the attached code but it doesn't close at this point. I need to click outside of the menu to close that dropdown options. Please help.
    <Button Style="{StaticResource AddButton}">
        <telerik:RadContextMenu.ContextMenu >
            <telerik:RadContextMenu EventName="Click" ItemsSource="{Binding NewEntityMenuItems}" StaysOpen="False">
                <telerik:RadContextMenu.ItemTemplate>
                    <DataTemplate>
                        <telerik:RadMenuItem Header="{Binding Text}" Command="{Binding MenuItemClickedCommand}" StaysOpenOnClick="False"></telerik:RadMenuItem>
                    </DataTemplate>
                </telerik:RadContextMenu.ItemTemplate>
            </telerik:RadContextMenu>
        </telerik:RadContextMenu.ContextMenu>
    </Button>

  2. Kalin
    Admin
    Kalin avatar
    1208 posts

    Posted 23 Jul 2014 Link to this post

    Hi Andy,

    The issue here is because of the used ItemTemplate. For this scenario you would need to use ItemContainerStyle with the desired properties set. Please check the following code snippet:

    <Button Content="Button">
        <telerik:RadContextMenu.ContextMenu >
            <telerik:RadContextMenu EventName="Click" ItemsSource="{Binding NewEntityMenuItems}" StaysOpen="False">
                <telerik:RadContextMenu.ItemContainerStyle>
                    <Style TargetType="telerik:RadMenuItem">
                        <Setter Property="Header" Value="{Binding Text}" />
                        <Setter Property="Command" Value="{Binding MenuItemClickedCommand}" />
                        <Setter Property="StaysOpenOnClick" Value="False" />
                    </Style>
                </telerik:RadContextMenu.ItemContainerStyle>
            </telerik:RadContextMenu>
        </telerik:RadContextMenu.ContextMenu>
    </Button>

    Hope this helps.

    Regards,
    Kalin
    Telerik
     
    Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
     
  3. UI for WPF is Visual Studio 2017 Ready
  4. Andy
    Andy avatar
    13 posts
    Member since:
    Apr 2014

    Posted 24 Jul 2014 in reply to Kalin Link to this post

    Thanks. It worked great! I have attached the image of the menu in my application. There is a gray rectangular  area (highlighted in the image with red color) along with the menu. How do we get rid of that. Let only the MenuItem Texts show up. 
  5. Kalin
    Admin
    Kalin avatar
    1208 posts

    Posted 25 Jul 2014 Link to this post

    Hi Andy,

    You would need to set the IconColumnWidth property of the ContextMenu to 0 in order to achieve the desired appearance.

    Hope this will work for you.

    Regards,
    Kalin
    Telerik
     
    Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
     
  6. Andy
    Andy avatar
    13 posts
    Member since:
    Apr 2014

    Posted 25 Jul 2014 in reply to Kalin Link to this post

    Thanks..It Worked great.
Back to Top
UI for WPF is Visual Studio 2017 Ready