8

I want my to have a sunken border like a textbox. How to do this? Is there a way to get the controltemplate to mimc the parent border?

David Basarab
  • 72,212
  • 42
  • 129
  • 156
Luis Aguilar
  • 4,331
  • 6
  • 36
  • 55

2 Answers2

12

There is no theme for you to use, but you can work around like this:

Using this MSDN model (http://i.msdn.microsoft.com/dynimg/IC84967.gif):

diagram of border styles

Here's my recommendation: (sunken inner)

Just change the height/width of the outside border and you use this block of XAML like a TextBox. Reverse the two border tags if you want an outder border instead. Should be easy for you.

<Border Width="100" Height="200" 
        BorderBrush="Gainsboro" BorderThickness="0,0,5,5">
    <Border BorderBrush="Gray" BorderThickness="5,5,0,0"> 
        <TextBox Text="Hello World" 
                 BorderThickness="0"
                 HorizontalAlignment="Stretch" 
                 VerticalAlignment="Stretch" />
    </Border>
</Border> 

Special thanks to: Style a border with a different brush color for each corner

Should look like this:

Sample of border-style example

Community
  • 1
  • 1
Jerry Nixon
  • 31,313
  • 14
  • 117
  • 233
  • If you are anxious for reusability, then a UserControl that inherits TextBox is just fine. – Jerry Nixon Sep 30 '11 at 16:02
  • I actually solved it by using all four borders. I was hoping I had not to create the borders manually, but well... – Luis Aguilar Sep 30 '11 at 16:22
  • I removed the BorderThickness-Attribute from TextBox, it's not available. Also IMO the two Border-Elements should be swapped. The upper right corner seems wrong to me compared to the Inset 3D-Border that WinForms creates. Not quite sure about the lower left corner either. – Hexo Oct 26 '16 at 11:40
1

You can try something like this

<Border Margin="20" BorderThickness="0.5" BorderBrush="Gray">
    <Border BorderThickness="1,1,0,0" BorderBrush="DarkGray">
        <ContentPresenter />
    </Border>
</Border>

You might need to play with the colours though.

Ray
  • 45,695
  • 27
  • 126
  • 169