Thursday, November 1, 2007

Remove control box of Paged WPF applications

  • Get the instance of the current Window from Application.Current and remove it's Control box by setting WindowStyle=None.

    public partial class Page1 : System.Windows.Controls.Page
    {
    public Page1()
    {

    this.Loaded += new RoutedEventHandler(Page1_Loaded);
    InitializeComponent();
    }

    void Page1_Loaded(object sender, RoutedEventArgs e)
    {
    Application.Current.MainWindow.WindowStyle = WindowStyle.None;
    }

    }

    Application.Current.MainWindow will be initialized only in Loaded event of Page

  • <Application.Resources>
    <Style TargetType ="{x:Type NavigationWindow}">
    <Setter Property ="WindowStyle" Value="None"/>
    </Style>
    </Application.Resources>

3 comments:

  1. Actually this removes the border of the window entirely, not only the controlbox (icon and system menu in the upper left).

    ReplyDelete
  2. BorderThickness="1" this will do if you want border

    ReplyDelete