Pavel
Pavel

Reputation: 153

WPF Border for ComboBox

I try to use a ComboBox based on ToolBar.ComboBoxStyleKey. It has a flat design. Control by default does not have a border, i.e., on a white background is only visible icon of ToggleButton. How can I add border for control when focus isn't on ComboBox?

Thanks!

No focus:

Combo Box without focus

Mouse hover:

Mouse Hover

Upvotes: 1

Views: 5529

Answers (2)

Maxime Tremblay-Savard
Maxime Tremblay-Savard

Reputation: 967

There is a Border control in WPF, you could use that to wrap around your ComboBox.

<Border Background="GhostWhite" BorderBrush="Gainsboro" BorderThickness="1">
    <ComboBox>
        ...
    </CombodBox>
</Border>

http://www.wpf-tutorial.com/misc-controls/the-border-control/

You could set the BorderThickness according to if the combobox has the focus or not.

Upvotes: 1

Adam
Adam

Reputation: 2440

There are countless options available.

  1. Draw a rectangle around the combobox's (x,y) coordinates.

  2. Make your own custom combobox as shown in: CustomCombowithBorder.

  3. Add a panel behind it and give the panel a border thus imitating a border.

  4. etc....

EDIT:

Found that MSDN gives an excellent answer as also shown in ComboBox Styling .

<Setter Property="Template">
   <Setter.Value>
      <ControlTemplate TargetType="ComboBox">
         <Grid>
            <Border x:Name="ContentPresenterBorder">
               <Grid>
                  <ToggleButton x:Name="DropDownToggle"/>
                  <ContentPresenter x:Name="ContentPresenter" />
                     <TextBlock Text=" " />
                  </ContentPresenter>
               </Grid>
            </Border>
         </Grid>
      </ControlTemplate>
   </Setter.Value>
</Setter>

Upvotes: 0

Related Questions