Context Menu not closing with RadDropDownButton

6 posts, 1 answers
  1. yonadav
    yonadav avatar
    60 posts
    Member since:
    Oct 2009

    Posted 16 May 2010 Link to this post

    Hi,

    We're using RadDropDownButton with a ContextMenu within a Grid:

        <telerik:RadGridView  
            RowIndicatorVisibility="Collapsed" 
            AutoGenerateColumns="False" 
            ShowGroupPanel="False"  
            RowDetailsVisibilityMode="VisibleWhenSelected" 
            Name="MainGrid" 
            ItemsSource="{Binding Alerts}" 
            ShowColumnHeaders="True" 
            ColumnWidth="*" 
            ScrollViewer.HorizontalScrollBarVisibility="Disabled" 
        > 
            <telerik:RadGridView.Columns> 
                <telerik:GridViewDataColumn  
                Name="Severity"  
                EditTriggers="None" 
                Width="30"
                    <telerik:GridViewDataColumn.CellTemplate> 
                        <DataTemplate> 
                            <StackPanel> 
                                <Image Source="{StaticResource CriticalAlertIcon}"  
                                   Style="{StaticResource IconImage}" 
                                   Visibility="{Binding IsCriticalSeverity, Converter={StaticResource VisibilityConverter_Collapsed}}" 
                                   ToolTip="Critical Alert" 
                                       /> 
                                <Image Source="{StaticResource HighAlertIcon}"  
                                   Style="{StaticResource IconImage}" 
                                   Visibility="{Binding IsErrorSeverity, Converter={StaticResource VisibilityConverter_Collapsed}}" 
                                   ToolTip="Error Alert" 
                                       /> 
                                <Image Source="{StaticResource MediumAlertIcon}"  
                                   Style="{StaticResource IconImage}" 
                                   Visibility="{Binding IsWarningSeverity, Converter={StaticResource VisibilityConverter_Collapsed}}" 
                                   ToolTip="Warning Alert" 
                                       /> 
                                <Image Source="{StaticResource LowAlertIcon}"  
                                   Style="{StaticResource IconImage}" 
                                   Visibility="{Binding IsInformationSeverity, Converter={StaticResource VisibilityConverter_Collapsed}}" 
                                   ToolTip="Informative Alert" 
                                       /> 
                                <Image Source="{StaticResource AutoremediationFailureAlertIcon}"  
                                   Style="{StaticResource IconImage}" 
                                   Visibility="{Binding IsAutoremediationFailed, Converter={StaticResource VisibilityConverter_Collapsed}}" 
                                   ToolTip="Autoremediation has failed" 
                                       /> 
                                <Image Source="{StaticResource AutoremediationSuccessfulAlertIcon}"  
                                   Style="{StaticResource IconImage}" 
                                   Visibility="{Binding IsAutoremediationSuccessful, Converter={StaticResource VisibilityConverter_Collapsed}}" 
                                   ToolTip="Autoremediation has succeeded" 
                                       /> 
                            </StackPanel> 
                        </DataTemplate> 
                    </telerik:GridViewDataColumn.CellTemplate> 
                </telerik:GridViewDataColumn> 
                <telerik:GridViewDataColumn Name="Id"  
                                        Header="Id" 
                                        EditTriggers="None" 
                                        MaxWidth="50"
                    <telerik:GridViewDataColumn.CellTemplate> 
                        <DataTemplate> 
                            <TextBlock 
                            Text="{Binding AlertId, Mode=OneWay}" 
                            TextWrapping="Wrap"/> 
                        </DataTemplate> 
                    </telerik:GridViewDataColumn.CellTemplate> 
                </telerik:GridViewDataColumn> 
                <telerik:GridViewDataColumn Name="Device"  
                                        Header="Device Name" 
                                        EditTriggers="None" 
                                        MaxWidth="150" 
                                        TextWrapping="Wrap"
                    <telerik:GridViewDataColumn.CellTemplate> 
                        <DataTemplate> 
                            <!-- We don't want the control to wrap --> 
                            <ContentControl 
                            DataContext="{Binding AssociatedViewModel, Mode=OneWay}" 
                            Content="{Binding}" 
                            ToolTip="{Binding Name}" 
                            Width="1000" 
                            /> 
                        </DataTemplate> 
                    </telerik:GridViewDataColumn.CellTemplate> 
                </telerik:GridViewDataColumn> 
                <telerik:GridViewDataColumn Name="Headline" 
                                        Header="Alert Headline" 
                                        EditTriggers="None" 
                                        MaxWidth="9999"
                    <telerik:GridViewDataColumn.CellTemplate> 
                        <DataTemplate> 
                            <StackPanel Orientation="Horizontal" Width="1500"
                                <TextBlock Text="WAITING FOR UPDATE: " FontWeight="Bold" 
                                           Visibility="{Binding IsWaitingForUpdate, Converter={StaticResource VisibilityConverter_Collapsed}}" /> 
                                <TextBlock Text="RESOLVED: "  
                                           Visibility="{Binding IsResolved, Converter={StaticResource VisibilityConverter_Collapsed}}" /> 
                                <common:IntelligentTextBlock  
                                    DataContext="{Binding Headline, Mode=OneWay}" 
                                    Width="1500" 
                                    ToolTip="{Binding}" 
                                    BubbleMouseEvents="True" 
                                    /> 
                            </StackPanel> 
                        </DataTemplate> 
                    </telerik:GridViewDataColumn.CellTemplate> 
                </telerik:GridViewDataColumn> 
                <telerik:GridViewDataColumn Name="LastUpdate"  
                                        Header="Last Update" 
                                        EditTriggers="None" 
                                        Width="140" 
                                        DataMemberBinding="{Binding LastUpdateDate,Mode=OneWay}" /> 
                <telerik:GridViewDataColumn Name="Resolve" 
                                        Header="Resolve" 
                                        EditTriggers="None" 
                                        Width="100"
                    <telerik:GridViewDataColumn.CellTemplate> 
                        <DataTemplate> 
                            <telerik:RadDropDownButton  
                                Name="ResolveButton" 
                                HorizontalContentAlignment="Center" 
                                VerticalContentAlignment="Center" 
                                Content="Resolve" 
                                Padding="3" 
                                Height="25" 
                                Unloaded="ResolveButton_Unloaded" 
                                > 
                                <telerik:RadDropDownButton.DropDownContent> 
                                    <telerik:RadContextMenu StaysOpen="False"
                                        <telerik:RadMenuItem Header="Sample Item"   
                                            ToolTip="Does something" 
                                            Command="{Binding DoCommand}"  
                                            StaysOpenOnClick="False" /> 
                                        <!-- More RadMenuItems... --> 
                                    </telerik:RadContextMenu> 
                                </telerik:RadDropDownButton.DropDownContent> 
                            </telerik:RadDropDownButton> 
                        </DataTemplate> 
                    </telerik:GridViewDataColumn.CellTemplate> 
                </telerik:GridViewDataColumn> 
            </telerik:RadGridView.Columns> 
            <telerik:RadGridView.RowDetailsTemplate> 
                <DataTemplate> 
                    <Grid DataContext="{Binding}"
                        <Grid.ColumnDefinitions> 
                            <ColumnDefinition Width="80"  /> 
                            <!-- The width of the Severity and ID columns --> 
                            <ColumnDefinition Width="*" /> 
                        </Grid.ColumnDefinitions> 
     
                        <!-- Darken the left margin: --> 
                        <Grid Background="Black" Opacity="0.4" /> 
     
                        <!-- The actual text --> 
                        <common:IntelligentTextBlock  
                            Grid.Column="1" 
                            DataContext="{Binding Description, Mode=OneWay}"  
                            /> 
                    </Grid> 
                </DataTemplate> 
            </telerik:RadGridView.RowDetailsTemplate> 
        </telerik:RadGridView> 
     

    The ContextMenu has many RadMenuItems, some of them with sub RadMenuItems as well. All of the items have commands. All items but one open a new Pane in the DocumentHost or open a new window. When these items are clicked, the context menu closes as it should.

    The problem: One item, the first in the list, does not cause the context menu to close when clicked. This item does not open a new window, nor does it open a new pane. As part of our debugging we've actually set an empty command for this menuitem to see if the command was causing any issues. It didn't help. The command is called, but the context menu is not closing. We can close it by clicking elsewhere in the view.

    We're using 2010 Q1 SP1, but this happens on 2010 Q1 as well.

    We've tried doing things like hooking the Click even for the menu item and then setting the IsOpen property of the context menu to False, but it didn't help.

    Any pointers?

    Thanks,
    yonadav

  2. Answer
    Tina Stancheva
    Admin
    Tina Stancheva avatar
    3298 posts

    Posted 19 May 2010 Link to this post

    Hello Yonadav,

    In the Click() event handler of the menu item, it is better to close the RadDropDownButton hosting the RadContextMenu. Can you try the following:
    private void RadMenuItem_Click(object sender, Telerik.Windows.RadRoutedEventArgs e)
    {
        RadMenuItem item = e.Source as RadMenuItem;
     
        RadDropDownButton btn = item.ParentOfType<RadDropDownButton>();
        if (btn != null )
            btn.IsOpen = false;
    }

    Please let me know if this is what you had in mind?

    Sincerely yours,
    Tina Stancheva
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  3. UI for WPF is Visual Studio 2017 Ready
  4. yonadav
    yonadav avatar
    60 posts
    Member since:
    Oct 2009

    Posted 20 May 2010 Link to this post

    Hi Tina,

    Exactly what we needed... thanks!

    yonadav
  5. Tina Stancheva
    Admin
    Tina Stancheva avatar
    3298 posts

    Posted 21 May 2010 Link to this post

    Hello yonadav,

    I am glad I was able to help.

    Let me know if I can further assit you.

    All the best,
    Tina Stancheva
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  6. Scott Shuppert
    Scott Shuppert avatar
    9 posts
    Member since:
    Feb 2010

    Posted 19 Jan 2011 Link to this post

    There any XAML-only solution for this problem?
  7. Scott Shuppert
    Scott Shuppert avatar
    9 posts
    Member since:
    Feb 2010

    Posted 19 Jan 2011 Link to this post

    Please skip my question. I was inherited from RadMenuItem and has implemented expected behaviour.
Back to Top
UI for WPF is Visual Studio 2017 Ready