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

DropDown button width in RadComboBox

6 Answers 429 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Jace
Top achievements
Rank 1
Jace asked on 31 Dec 2016, 04:48 PM
I'm looking for a simple way to increase the DropDown button width in the RadComboBox. I've seen a number of styling solutions that consist of like two or three hundred lines of XAML. Is there an easier way to achieve this?

6 Answers, 1 is accepted

Sort by
0
Ivan Ivanov
Telerik team
answered on 02 Jan 2017, 11:15 AM
Hello,

I believe that you are referring to solutions that require modifications of the ControlTemplate. Generally, this is a standard approach when visually modifying WPF controls. To avoid the complication of a View's structure, you can assign the modified template through a separate Style and separate the Style definition in a separate resource dictionary file. However, you still have a few other options, if you want to avoid this.
You can defined an implicit style that targets RadToggleButton in an appropriate resource scope. For instance, if you want to affect only one instance of RadComboBox that you want to customize, you can set it like this:
<telerik:RadComboBox . . .>
            <telerik:RadComboBox.Resources>
                <Style TargetType="telerik:RadToggleButton">
                    <Setter Property="Width" Value="300" />
                </Style>
            </telerik:RadComboBox.Resources>
        </telerik:RadComboBox>
Anothe option is to set it at run-time. You can subscribe to the control's Loaded event, find the button on the event's occurrence and set the fixed width.

Regards,
Ivan Ivanov
Telerik by Progress
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
0
Jace
Top achievements
Rank 1
answered on 02 Jan 2017, 03:03 PM

This was a breeze to implement.

Thanks, Ivan.  I appreciate it.

0
Jace
Top achievements
Rank 1
answered on 02 Jan 2017, 03:47 PM

Ivan,

I'm able to set the RadToggleButton property through XAML, but struggle to apply it through code via the controls loaded event.

private void rcb_Loaded(object sender, RoutedEventArgs e)
{
     var rcb = sender as RadComboBox; 
     Style style = new Style() { TargetType = typeof(RadToggleButton) };
     style.Setters.Add(new Setter() { Property = WidthProperty, Value = 80 });
     rcb.Style = style;
}
0
Ivan Ivanov
Telerik team
answered on 02 Jan 2017, 03:54 PM
Hello,

It would be easier to set the property value directly instead of using a style. To find the button in the visual tree, you can use Telerik.Windows.Controls.ChildrenOfType<T>, which is a very handy method:
private void RadComboBox_Loaded(object sender, RoutedEventArgs e)
{
    (sender as RadComboBox).ChildrenOfType<RadToggleButton>().First().Width = 80;
}


Regards,
Ivan Ivanov
Telerik by Progress
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
0
Jace
Top achievements
Rank 1
answered on 02 Jan 2017, 04:27 PM

For heaven sake. That was too easy.

Thanks, Ivan...  I wish you a great 2017!

0
Ivan Ivanov
Telerik team
answered on 02 Jan 2017, 04:38 PM
Hi,

You too! I was glad to help.

Regards,
Ivan Ivanov
Telerik by Progress
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
Tags
ComboBox
Asked by
Jace
Top achievements
Rank 1
Answers by
Ivan Ivanov
Telerik team
Jace
Top achievements
Rank 1
Share this question
or