This is a migrated thread and some comments may be shown as answers.

SplitButton stays open on click

1 Answer 127 Views
Buttons
This is a migrated thread and some comments may be shown as answers.
Chris
Top achievements
Rank 1
Chris asked on 11 Feb 2012, 06:50 AM
Hi - I have this split button with 3 menu items. When I click on one of the menu items, I'm expecting the dropdown to close. I tried creating a template which sets StaysOpenOnClick="False", also tried setting it to false directly on each menu item but the dropdown continues to stay open. I've also tried handling the Click event to close the button. Nothing seems to work. Any ideas?

Here is the style I tried: 
<Style TargetType="telerik:RadMenuItem">
    <Setter Property="Header" Value="{Binding RelativeSource={RelativeSource Self}, Path=Command.DisplayName, Mode=OneWay}" />
    <Setter Property="ToolTip" Value="{Binding RelativeSource={RelativeSource Self}, Path=Command.Description, Mode=OneWay}" />
    <Setter Property="StaysOpenOnClick" Value="False" />
 </Style>

Here is the click handler I tried:

        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;
            }
        }

Here is the SplitButton:
<telerik:RadSplitButton Command="{Binding Path=ThisButtonComman}"
                                    ToolTip="Default action."
                                    Content="Click this button"
                                    Height="25"
                                    Margin="10,5,0,5"
                                    AutomationProperties.AutomationId="SweetSplitButton"
                                    AutomationProperties.Name="Sweet split button.">
        <telerik:RadSplitButton.DropDownContent>
          <telerik:RadMenu telerik:StyleManager.Theme="Summer" Background="Transparent" Orientation="Vertical">
            <telerik:RadMenuItem Command="{Binding Path=Command1}"
                                       AutomationProperties.AutomationId="Id1"
                                       AutomationProperties.Name="Name1." />
            <telerik:RadMenuItem Command="{Binding Path=Command1}"
                                       AutomationProperties.AutomationId="Id2"
                                       AutomationProperties.Name="Name2." />
            <telerik:RadMenuItem Command="{Binding Path=Command3}"
                                       AutomationProperties.AutomationId="Id3"
                                       AutomationProperties.Name="Name3." />            
          </telerik:RadMenu>
        </telerik:RadSplitButton.DropDownContent>
      </telerik:RadSplitButton>

Thanks,
Chris

1 Answer, 1 is accepted

Sort by
0
Zarko
Telerik team
answered on 15 Feb 2012, 04:43 PM
Hello,

 The style didn't work because the StaysOpenOnClick property is used when you have hierarchical RadMenu (with RadMenuItems inside other RadMenuItems). As for the event - the problem is that you search for parents of type RadDropDownButton, but you should search for RadSplitButton:

RadMenuItem item = e.Source as RadMenuItem;
RadSplitButton btn = item.ParentOfType<RadSplitButton>();
if (btn != null)
{
    btn.IsOpen = false;
}
If you need further assistance please feel free to ask.All the best,
Zarko
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
Tags
Buttons
Asked by
Chris
Top achievements
Rank 1
Answers by
Zarko
Telerik team
Share this question
or