Nested RadRibbonDropDownButtons - odd behavior.

2 posts, 0 answers
  1. scott
    scott avatar
    67 posts
    Member since:
    Jul 2010

    Posted 21 Nov 2012 Link to this post

    I have a ribbon looking like this:
    <UserControl x:Class="q_telerik2.MainPage"
    mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480">
    <Grid x:Name="LayoutRoot">
    <telerik:RadRibbonView>
    <telerik:RadRibbonTab>
    <telerik:RadRibbonGroup>
    <telerik:RadRibbonDropDownButton Name="ribbonButton" DropDownOpening="RadRibbonDropDownButton_DropDownOpening" Content="Click Me">
    </telerik:RadRibbonDropDownButton>
    </telerik:RadRibbonGroup>
    </telerik:RadRibbonTab>
    </telerik:RadRibbonView>
    </Grid>
    </UserControl>




    And I populate it like this:

    private void RadRibbonDropDownButton_DropDownOpening(object sender, RoutedEventArgs e)
    {
        StackPanel sp = new StackPanel();
        for (int i = 1; i < 5; i++)
        {
            RadDropDownButton childButton = new RadDropDownButton() { Content = "Choice " + i.ToString() };
            sp.Children.Add(childButton);
     
            StackPanel childContent = new StackPanel();
            for (int j=1 ; j<5; j++)
            {
                TextBlock tb = new TextBlock() { Text = j.ToString() + ".  Why do we display up here?" };
                childContent.Children.Add(tb);
            }
            childButton.DropDownContent = childContent;
        }
        ribbonButton.DropDownContent = sp;
    }


    The TextBlock content doesn't display near its parent drop down button, but at {0,0} of the window...

    I've attached a pic of what I see.  Is this something I'm doing wrong or is there a workaround?

    Thanks -







  2. Kiril Vandov
    Admin
    Kiril Vandov avatar
    324 posts

    Posted 23 Nov 2012 Link to this post

    Hi Scott,

    When we use RoutedEvents and both the parent and the children share same events, we have to assure that the sender and the original source are equal otherwise the event will be called again when we try to open the nested buttons. I added the needed verification, here is a code snippet  for it:

    private void RadRibbonDropDownButton_DropDownOpening(object sender, RoutedEventArgs e)
    {
        var button = (e as RadRoutedEventArgs).OriginalSource as RadDropDownButton;
        if (button == sender)
        {
            StackPanel sp = new StackPanel();
            for (int i = 1; i < 5; i++)
            {
                RadDropDownButton childButton = new RadDropDownButton() { Content = "Choice " + i.ToString() };
     
                StackPanel childContent = new StackPanel();
                for (int j = 1; j < 5; j++)
                {
                    TextBlock tb = new TextBlock() { Text = j.ToString() + ".  Why do we display up here?" };
                    childContent.Children.Add(tb);
                }
                childButton.DropDownContent = childContent;
                sp.Children.Add(childButton);
            }
            button.DropDownContent = sp;
        }
    }
    Hope this helps. Please let us know if you need more info.

    Regards,
    Kiril Vandov
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  3. DevCraft banner
Back to Top