How to modify the width of combo box scroll bar?

929Free 281 Reputation points
2021-05-06T00:50:39.193+00:00

hi, I want to modify the width of combo box control scroll bar. thanks .

Windows Presentation Foundation
Windows Presentation Foundation
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
2,768 questions
0 comments No comments
{count} votes

Accepted answer
  1. DaisyTian-1203 11,621 Reputation points
    2021-05-06T02:22:30.353+00:00

    You can use below methods to modify the width of comboBox ScrollBar.
    Method 1:

      <ComboBox Name="com"   
                      HorizontalAlignment="Left"   
                      Margin="335,176,0,0"   
                      VerticalAlignment="Top"   
                      MaxDropDownHeight="100"  
                      Width="130" >  
                <ComboBox.Resources>  
                    <Style TargetType="{x:Type ScrollViewer}">  
                        <Setter Property="OverridesDefaultStyle" Value="True"/>  
                        <Setter Property="VerticalScrollBarVisibility" Value="Visible"></Setter>  
                        <Setter Property="HorizontalScrollBarVisibility" Value="Visible"></Setter>  
                        <Setter Property="Template">  
                            <Setter.Value>  
                                <ControlTemplate TargetType="{x:Type ScrollViewer}">  
                                    <Grid>  
                                        <Grid.ColumnDefinitions>  
                                            <ColumnDefinition Width="Auto"/>  
                                            <ColumnDefinition/>  
                                        </Grid.ColumnDefinitions>  
                                        <Grid.RowDefinitions>  
                                            <RowDefinition/>  
                                            <RowDefinition Height="Auto"/>  
                                        </Grid.RowDefinitions>  
                                        <ScrollContentPresenter Grid.Column="1"/>  
                                        <ScrollBar Name="PART_VerticalScrollBar"  Grid.Row="0" Grid.Column="1" Orientation="Vertical" HorizontalAlignment="Right"    
                                                   Width="38" Value="{TemplateBinding VerticalOffset}"  
                                                   Maximum="{TemplateBinding ScrollableHeight}" ViewportSize="{TemplateBinding ViewportHeight}"   
                                                   />  
                                        <ScrollBar Name="PART_HorizontalScrollBar"  Grid.Row="1" Grid.Column="1"    
                                                   Orientation="Horizontal" Value="{TemplateBinding HorizontalOffset}"   
                                                   Maximum="{TemplateBinding ScrollableWidth}"   
                                                   ViewportSize="{TemplateBinding ViewportWidth}"/>  
                                    </Grid>  
                                </ControlTemplate>  
                            </Setter.Value>  
                        </Setter>  
                    </Style>  
                    <Style TargetType="Popup">  
                        <Setter Property="Width" Value="130"/>  
                    </Style>  
                     
                </ComboBox.Resources>  
            </ComboBox>  
    

    Method 2: Add namespace xmlns:sys="clr-namespace:System;assembly=mscorlib"

     <ComboBox Name="com2"   
                      HorizontalAlignment="Left"   
                      VerticalAlignment="Top"   
                      MaxDropDownHeight="100"  
                      Margin="30 100 20 100"  
                      Width="130" >  
                <ComboBox.Resources>  
                    <sys:Double x:Key="{x:Static SystemParameters.VerticalScrollBarWidthKey}">50</sys:Double>  
                    <sys:Double x:Key="{x:Static SystemParameters.HorizontalScrollBarHeightKey}">50</sys:Double>  
                </ComboBox.Resources>  
            </ComboBox>  
    

    Method 3:

     <ComboBox Name="com3"   
                      HorizontalAlignment="Left"   
                      VerticalAlignment="Top"   
                      MaxDropDownHeight="100"  
                      Width="130" >  
                <ComboBox.Resources>  
                    <Style x:Key="{x:Type ScrollBar}" TargetType="{x:Type ScrollBar}">  
                        <Setter Property="Stylus.IsFlicksEnabled" Value="True" />  
                        <Style.Triggers>  
                            <Trigger Property="Orientation" Value="Horizontal">  
                                <Setter Property="Height" Value="35" />  
                                <Setter Property="MinHeight" Value="40" />  
                            </Trigger>  
                            <Trigger Property="Orientation" Value="Vertical">  
                                <Setter Property="Width" Value="35" />  
                                <Setter Property="MinWidth" Value="40" />  
                            </Trigger>  
                        </Style.Triggers>  
                    </Style>  
                </ComboBox.Resources>  
            </ComboBox>  
    

    If the response is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


1 additional answer

Sort by: Most helpful
  1. Oscar Vargas 1 Reputation point
    2022-10-21T17:14:21.8+00:00

    Excellent answers, works like a champ

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.