Home > other >  How to remove the ComboBox Drop-Down button programmatically?
How to remove the ComboBox Drop-Down button programmatically?

Time:01-08

I want to remove the drop-down button on my dynamically created ComboBoxes, I could only find one topic discussing the matter here: WPF ComboBox without drop-down button, but it only had a XAML solution.

I logically went through every possible step to reproduce the logical access tree and reached the solution myself and would like to share, since there is no duplicate of this on stack overflow.

CodePudding user response:

The solution:

VB.Net:

    Dim myDouble As Double = 0
    Dim myStatic As ResourceKey = SystemParameters.VerticalScrollBarWidthKey
    myComboBox.Resources.Add(myStatic, myDouble)

C#:

{
    double myDouble = 0;
    ResourceKey myStatic = SystemParameters.VerticalScrollBarWidthKey;
    myComboBox.Resources.Add(myStatic, myDouble);
}

The XAML code I analyzed:

<ComboBox xmlns:sys="clr-namespace:System;assembly=mscorlib">
    <ComboBox.Resources>
        <sys:Double x:Key="{x:Static SystemParameters.VerticalScrollBarWidthKey}">0</sys:Double>
    </ComboBox.Resources>
    <ComboBoxItem>One</ComboBoxItem>
    <ComboBoxItem>Two</ComboBoxItem>
    <ComboBoxItem>Three</ComboBoxItem>
</ComboBox>

It was quite simple to reproduce, but finding the types was a hassle.

  •  Tags:  
  • Related