0

How can I be able to place buttons over windows border.What I am trying to do is to place close and minimize buttons over the border in a WPF application in c#.Any one could please tell me how to do that.

Sarita
  • 13
  • 2
  • 9
  • possible duplicate of [Adding button to titlebar (like Firefox 4) in VB.NET & WPF or WinForms on XP or Vista/7](http://stackoverflow.com/questions/6116553/adding-button-to-titlebar-like-firefox-4-in-vb-net-wpf-or-winforms-on-xp-or) – H.B. Feb 13 '12 at 11:23
  • How you are creating your application or windows for this UI? can you post some sample code? – Kishore Kumar Feb 13 '12 at 12:23

1 Answers1

0

The word 'Border' in the context of WPF may have two meanings. It may be the <Border> element, or it is possible you mean the area the defines the <Window> element. Which one is it?

If you just want to have a buttons on a <Border> element, just put it as the content of the element. If you have more than one buttons, you need to have a panel (e.g. <StackPanel>).

You cannot draw anything beyond the client area of a <Window> element. To have buttons outside the Window area, you should another Window (say 'toolwindow') with the buttons that you want. Most likely you want this toolwindow without caption and non resizable border: WindowStyle="None" ResizeMode="NoResize". Then, keep the tool window position in sync with your main window (best thing would be to bind the Left and Right properties of both Windows to Left and Right properties in a common data context. Don't forget to declare the Binding mode to BothWay).

EDIT (follow clarification from @Sarita):
So it is the first. By Content I meant the body of the XML element. Technically, it is the Child property of the Border element. The following two XAMLs are equivalent:

<Border Background="Green" Padding="5">
    <StackPanel>
        <Button>A</Button>
        <Button>B</Button>
    </StackPanel>
</Border>


<Border x:Name="Bord" Background="Green" Padding="5">
    <Border.Child>
        <StackPanel>
            <Button>A</Button>
            <Button>B</Button>
        </StackPanel>
    </Border.Child>
</Border>
Uri London
  • 10,631
  • 5
  • 51
  • 81
  • Thanks for your valuable help I was saying about border element present in WPF.Content is not a property of elements, so above thing won't work.Could you suggest me any other simple way. – Sarita Feb 13 '12 at 13:31
  • I have tried it before but the problem is I am not able to position the buttons in their exact positions where they should be.I have changed the orientation of stack panel to Horizontal.While setting the margin property of one button to place it in its correct place other button is also moving with respect to the first one. – Sarita Feb 14 '12 at 05:52
  • @Sarita, your positioning problem isn't specific to Border, but to StackPanel. In a StackPanel buttons goes one after the other in horizontal or vertical order. There are other panels, such as Grid and Canvas. If you want to control the exact positioning try to use the Canvas panel, with the Top and Left properties. – Uri London Feb 14 '12 at 06:00
  • I am new to WPF so it was a great help,It is working.Thanks @Uri. – Sarita Feb 14 '12 at 08:04