3D Border
How can I place a 3D border arround my control
Thanks
Answers
Placing a border around a control is as simple as wrapping your control in a <Border> element.
<Border BorderBrush='Red' BorderThickness='2'> <Label>Hello</Label> </Border>Some controls have built-in borders available via properties.
<Label BorderBrush='Red' BorderThickness='2' />
Your question is more specific though. How do you add a 3D border around my control?I'd have to ask you what you mean when you say 3D. Do you mean an etched border like you have in WinForms or something else? In WPF we have real 3D capabilties. Do you want to wrap your control in a 3D sphere or other 3D shape?
All Replies
Placing a border around a control is as simple as wrapping your control in a <Border> element.
<Border BorderBrush='Red' BorderThickness='2'> <Label>Hello</Label> </Border>Some controls have built-in borders available via properties.
<Label BorderBrush='Red' BorderThickness='2' />
Your question is more specific though. How do you add a 3D border around my control?I'd have to ask you what you mean when you say 3D. Do you mean an etched border like you have in WinForms or something else? In WPF we have real 3D capabilties. Do you want to wrap your control in a 3D sphere or other 3D shape?
I need something equivelant to Border3DStyle in System.Windows.Forms.
Thanks,
- I've been wondering the same thing. It's not a showstopper, but it does seem like a strange oversight that such a pervasive feature of WinForms would be so noticeably absent from WPF.
Here is a quick version that should look like what you want.
Code Block<Grid Background='LightGray'>
<Border Width='80 Height='40'
BorderBrush='Black'
BorderThickness='.25,.25,0,0'><Border BorderBrush='White'
BorderThickness='0,0,.25,.25'>
<Label>Sample</Label>
</Border>
</Border>
</Grid>
For a more reusable approach you could create a control template or make a custom decorator class (simliar to the built-in border) to wrap your controls.
- Proposed As Answer byAdrianoF Sunday, July 12, 2009 3:27 PM
Patrick Sears wrote: I've been wondering the same thing. It's not a showstopper, but it does seem like a strange oversight that such a pervasive feature of WinForms would be so noticeably absent from WPF. The WPF approach is more flexible. You can compose your UI from the elements built into WPF. If you've spent time building Winforms applications however you'll run across examples like this where you think 'how come this isn't available'.
Example: In WPF there is no Image property on a Button control. In Winforms, of course, there is.
That's because in WPF it is easy to create a Image element and nest it inside a Button element. Then use all the power of the layout engine (panels, padding, margins, transforms etc) to dictate how and where the image is rendered. The big benefit from this approach is that the Button control author didn't have to modify his Button class to accomodate your need to add a Image inside his control.
The drawback to this approach is that you have to learn more about how the WPF framework works and spend more time composing your interface. Templates and custom decorators can help if you want to build reusable items.
I saw Patrick Sears's sample for creating 3D border, but is this the correct way. I think in this way we 1000 steps back. Before in API we used this way to draw 3D-Border before using DrawEdge. we used to draw two lines one is black and the other is white. Now it seem we will use this way again. so if someone don’t know how is 3D-Border. he will never do this. we are programmer's and i don’t care in details how the 3D border is done. I just want a method or template to do that.
When we left APIs behind and starting working on .Net, before writing any code, the first thing must be in our mind is " .Net Frame work may be has method to do our work and we don’t need to re-vent the weal" now its seem that we will re-vent the weal again
- Sam,
You mean Walt Ritscher's sample? I didn't provide code for one.
At any rate, I agree with you. This is what I meant when I said I'm astonished that it's not there. I recognize that you have the flexibility to create it yourself, but that's the whole point of having pre-installed styles - you only re-invent the wheel when the existing code doesn't do what you want. oh sorry, its Walt Ritscher's sample.


