DropDown button width in RadComboBox

7 posts, 0 answers
  1. Jace
    Jace avatar
    13 posts
    Member since:
    Feb 2015

    Posted 31 Dec 2016 Link to this post

    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?
  2. Ivan Ivanov
    Admin
    Ivan Ivanov avatar
    1195 posts

    Posted 02 Jan Link to this post

    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.
  3. Jace
    Jace avatar
    13 posts
    Member since:
    Feb 2015

    Posted 02 Jan in reply to Ivan Ivanov Link to this post

    This was a breeze to implement.

    Thanks, Ivan.  I appreciate it.

  4. Jace
    Jace avatar
    13 posts
    Member since:
    Feb 2015

    Posted 02 Jan in reply to Ivan Ivanov Link to this post

    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;
    }
  5. Ivan Ivanov
    Admin
    Ivan Ivanov avatar
    1195 posts

    Posted 02 Jan Link to this post

    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.
  6. Jace
    Jace avatar
    13 posts
    Member since:
    Feb 2015

    Posted 02 Jan in reply to Ivan Ivanov Link to this post

    For heaven sake. That was too easy.

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

  7. Ivan Ivanov
    Admin
    Ivan Ivanov avatar
    1195 posts

    Posted 02 Jan Link to this post

    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.
Back to Top