Ask a questionAsk a question
 

Answer3D Border

Answers

  • Sunday, September 30, 2007 8:18 PMWalt RitscherMVPUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

    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

  • Sunday, September 30, 2007 8:18 PMWalt RitscherMVPUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

    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?

     

  • Sunday, September 30, 2007 10:04 PMSam Andy Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    I need something equivelant to  Border3DStyle in System.Windows.Forms.

     

    Thanks,

     

     

  • Monday, October 01, 2007 2:50 AMPatrick Sears Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    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.
  • Monday, October 01, 2007 5:05 PMWalt RitscherMVPUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Proposed Answer

    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
    •  
  • Monday, October 01, 2007 5:30 PMWalt RitscherMVPUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

     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.

     

  • Monday, October 01, 2007 10:13 PMSam Andy Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    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

  • Monday, October 01, 2007 10:28 PMPatrick Sears Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    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.
  • Monday, October 01, 2007 10:40 PMSam Andy Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    oh sorry, its Walt Ritscher's sample.