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

RadDropDownButton DropDownContent not shown when Visibililty of RadDropDown is collapsed and calling IsOpen=true after setting Visibility to Visible

2 Answers 231 Views
Buttons
This is a migrated thread and some comments may be shown as answers.
Martin
Top achievements
Rank 1
Martin asked on 18 Feb 2021, 10:26 AM

Hello,
when I try to open the DropDownContent of a RadDropDownButton in code behind then the DropDownContent is not shown after change visibility of the RadDropDown Button from collapsed to visible.

See following code example:

    <StackPanel>
    <telerik:RadDropDownButton
                                               DropDownPlacement="Bottom"
                  Visibility="Collapsed"
                  x:Name="btnDropDown"
                  Margin="0 0 0 5" Padding="0" Content="Some Header">
        <telerik:RadDropDownButton.DropDownContent>
            <ListBox Background="LightGoldenrodYellow" >
                <ListBoxItem Content="Item 1" />
                <ListBoxItem Content="Item 2"/>
                <ListBoxItem Content="Item 3" />
            </ListBox>
        </telerik:RadDropDownButton.DropDownContent>
    </telerik:RadDropDownButton>
 
    <Button Click="Button_Click">Show ListBox in DropDownButton</Button>
</StackPanel>

in code behind:

private void Button_Click(object sender, RoutedEventArgs e)
{
    btnDropDown.SetCurrentValue(VisibilityProperty, Visibility.Visible);
    btnDropDown.SetCurrentValue(RadDropDownButton.IsOpenProperty, true);
}

 

Result:

The btnDropDown appears on the window and act like opened but the DropDownContent is not shown.


2 Answers, 1 is accepted

Sort by
0
Accepted
Martin Ivanov
Telerik team
answered on 23 Feb 2021, 09:09 AM

Hello Martin,

In order for the DropDownContent to display properly the control should be rendered. Setting the Visibility property doesn't directly render the control, but it schedules the process will is going to happen on the next available layout pass. This said, setting the IsOpen property right after the Visibility is too early, so you will need to wait a bit. One way to do this is to use a dispatcher. For example:

private void Button_Click(object sender, RoutedEventArgs e)
{
	btnDropDown.SetCurrentValue(VisibilityProperty, Visibility.Visible);
	Dispatcher.BeginInvoke(new Action(() =>
	{
		btnDropDown.SetCurrentValue(RadDropDownButton.IsOpenProperty, true);
	}), System.Windows.Threading.DispatcherPriority.Background);
}

Can you please try this approach and let me know if it helps?

Regards,
Martin Ivanov
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

0
Martin
Top achievements
Rank 1
answered on 24 Feb 2021, 02:58 PM

Hello Martin,

thanks for the response.

I modified your approach and now it works properly.

btnDropDown.Dispatcher.InvokeAsync(new Action(() =>
              {
                  btnDropDown.IsOpen = true;
              }), DispatcherPriority.Background);

 

 

Thanks!

 

Kind regards,
Martin

Tags
Buttons
Asked by
Martin
Top achievements
Rank 1
Answers by
Martin Ivanov
Telerik team
Martin
Top achievements
Rank 1
Share this question
or