Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting a Border Control to Have Sunken Border

Tags:

wpf

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?

like image 354
Luis Aguilar Avatar asked Sep 30 '11 15:09

Luis Aguilar


2 Answers

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

like image 89
Jerry Nixon Avatar answered Oct 10 '22 01:10

Jerry Nixon


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.

like image 30
Ray Avatar answered Oct 10 '22 03:10

Ray