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?
Asked
Active
Viewed 9,065 times
8
-
Do you have an example? The TextBox just has a plain border. – Ray Sep 30 '11 at 15:40
-
The textbox in WindowsXP has sunken WinForms-style border. – Luis Aguilar Sep 30 '11 at 15:41
-
It doesn't for me. But I get what you mean. I see the same effect in Lotus notes. – Ray Sep 30 '11 at 15:47
-
I was able to get a nice-looking result, described [here][1]. [1]: http://stackoverflow.com/a/11767188/718325 – Jason Frank Aug 01 '12 at 20:52
2 Answers
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):
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:

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
-
I was hoping to use the border from the current theme. You know like the current Windows look & feel stuff. – Luis Aguilar Sep 30 '11 at 15:48