none
Getting rid of Window Border

    Pregunta

  • I am making a custom-draw window in which I manage all the border drawing and window resizing, etc.  

    So to achieve removing the "standard" window border, I set WindowStyle.None.  This of course leaves a bevelled border in XP.  It seems that setting either AllowsTransparency=True or ResizeMode=NoResize will get rid of that bevelled border.

    Now here is the problem...  I can't set AllowsTransparency to true because that prevents Windows Forms controls from being visible in the Window.  I can't set ResizeMode=NoResize either because if you do that then right clicking on the taskbar will not give you Maximize/Minimize/etc. options, which I do still need since my window is resizable (via my own handling).

    Anyone have any idea how to get rid of that border without using either AllowsTransparency or ResizeMode?

    lunes, 17 de enero de 2011 8:02

Respuestas

  • Hi Deepak Bhardwaj,

    I suggest you to set the ResizeMode=NoResize and WindowStyle.None.

    In order to make your WPF window resizable, you may take advantage of WPF Shell Integration Library which enables you to change the WindowChrome of the window. 

    You may write your window XAML like below,

    <Window x:Class="WpfApplication1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"    
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:shell="clr-namespace:Microsoft.Windows.Shell;assembly=Microsoft.Windows.Shell"
        Title="MainWindow" WindowStyle="None" Height="350" Width="525" >
      <shell:WindowChrome.WindowChrome>
        <shell:WindowChrome ResizeBorderThickness="10" CornerRadius="0" GlassFrameThickness="0" CaptionHeight="30"/>
      </shell:WindowChrome.WindowChrome>
      <Grid Name="grid">
        
      </Grid>
    </Window>
    
    

    As you could see, there is a Non-client area for Caption bar. This area could be dragged to move the window. I suggest you add the very same caption bar into your app.

    Hope this information is helpful for you! If you still have any doubts or questions please feel free to let me know.

     

    Best regards


    Yves Zhang [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    viernes, 21 de enero de 2011 11:25
    Moderador

Todas las respuestas

  • Hi Deepak,

    To get rid of the border you will have to use AllowsTransparency=True. Also I could not open the link you have given above.

    Regards,


    Parvez Ansari WPF + Silverlight 4.0 Themes www.nukeation.com Blog : www.wpfblogger.com
    lunes, 17 de enero de 2011 11:09
  • As I already mentioned in my post that I can't set AllowTransparency=True because I am hosting a WinForms control in my window using WindowsFormsHost control. After setting AllowTransparency=True WinForms control are not visible to WPF Window.
    IGNOU BUZZ
    ANALEC Infotech Pvt. Ltd.
    lunes, 17 de enero de 2011 11:39
  • Hi,

    I totally understand what you are mentioning, but I cannot find an answer which fits both criteria.

    Just wanted to share a thread I had come across, I don't know whether you have seen it or not http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/f64b9912-a410-4b12-94a3-74c71c4aeaa1

    Hope this helps.


    Parvez Ansari WPF + Silverlight 4.0 Themes www.nukeation.com Blog : www.wpfblogger.com
    lunes, 17 de enero de 2011 11:47
  • Hi Deepak Bhardwaj,

    I suggest you to set the ResizeMode=NoResize and WindowStyle.None.

    In order to make your WPF window resizable, you may take advantage of WPF Shell Integration Library which enables you to change the WindowChrome of the window. 

    You may write your window XAML like below,

    <Window x:Class="WpfApplication1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"    
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:shell="clr-namespace:Microsoft.Windows.Shell;assembly=Microsoft.Windows.Shell"
        Title="MainWindow" WindowStyle="None" Height="350" Width="525" >
      <shell:WindowChrome.WindowChrome>
        <shell:WindowChrome ResizeBorderThickness="10" CornerRadius="0" GlassFrameThickness="0" CaptionHeight="30"/>
      </shell:WindowChrome.WindowChrome>
      <Grid Name="grid">
        
      </Grid>
    </Window>
    
    

    As you could see, there is a Non-client area for Caption bar. This area could be dragged to move the window. I suggest you add the very same caption bar into your app.

    Hope this information is helpful for you! If you still have any doubts or questions please feel free to let me know.

     

    Best regards


    Yves Zhang [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    viernes, 21 de enero de 2011 11:25
    Moderador