none
Is there a way to remove the "red x" button from the title bar in a WPF application?

    Question

  • Hello,

    For some reason when I close my application with the "red x" the process continues to run. This causes a build error when I try to relaunch the application.

    If I exit the application through my self-designed exit button the application closes and the processes stop.

     

     

    private void btnExit_Click(object sender, RoutedEventArgs e)

    {

     

     

    Application.Current.Shutdown();

    }

    Since I am not savvy enough yet with C# to understand what I am doing wrong, but I know that the problem is solved via using my button, I just want to remove the "red x" to prevent this problem from ever occuring.

    Thank you in advance if you take the time to help me with this one.

    • Moved by Rudedog2MVP Wednesday, December 08, 2010 1:37 AM Move to more appropriate forum (From:Visual C# General)
    Wednesday, December 08, 2010 12:24 AM

Answers

  • <Application x:Class="xxx.App"
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
      xmlns:sys="clr-namespace:System;assembly=mscorlib"
      ShutdownMode="OnLastWindowClose"
     >
    doing that will yield some other undesired effects.   One of the undesired effects is not being able to move your application window around.  Secondly you won't be able change the size to full screen.  One thing you can try is the ShutdownMode="OnLastWindowClose" that should effectively kill the AppDomain on calling Application.Current.ShutDown().

    <Window x:Class="TestApp.Views.ShellView"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"    
    
    Height="768" Width="1024" Closed="Window_Closed" Closing="Window_Closing">  
     private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {
          MessageBox.Show("We have been told to shut down");
        }
    
        private void Window_Closed(object sender, EventArgs e)
        {
          MessageBox.Show("Closed Event");
        }

    These 2 events here are associated with the "Red X" at the upper right corner.  These can be used to flag the user if they sure they want to quit and then process anything to save if they do.

     

    Hope this helps...

    Wednesday, December 08, 2010 6:11 AM

All replies

  • Set  WindowStyle="None" in your window Tag in the XAML markup

    Devlin Liles http://twitter.com/devlinliles http://www.devlinliles.com/ If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".
    Wednesday, December 08, 2010 1:20 AM
  • <Application x:Class="xxx.App"
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
      xmlns:sys="clr-namespace:System;assembly=mscorlib"
      ShutdownMode="OnLastWindowClose"
     >
    doing that will yield some other undesired effects.   One of the undesired effects is not being able to move your application window around.  Secondly you won't be able change the size to full screen.  One thing you can try is the ShutdownMode="OnLastWindowClose" that should effectively kill the AppDomain on calling Application.Current.ShutDown().

    <Window x:Class="TestApp.Views.ShellView"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"    
    
    Height="768" Width="1024" Closed="Window_Closed" Closing="Window_Closing">  
     private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {
          MessageBox.Show("We have been told to shut down");
        }
    
        private void Window_Closed(object sender, EventArgs e)
        {
          MessageBox.Show("Closed Event");
        }

    These 2 events here are associated with the "Red X" at the upper right corner.  These can be used to flag the user if they sure they want to quit and then process anything to save if they do.

     

    Hope this helps...

    Wednesday, December 08, 2010 6:11 AM
  • Hi RobertOfRome,

    Welcome to our forum.

    Have you tried mvermef's solution, whether it can resolve your issue?

    If not, could you give me a feedback, and share more information with me, I will do my best to resolve your issue as soon as possible.

     

    Best regards,


    Sheldon _Xiao [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.

    Monday, December 13, 2010 11:03 AM
    Moderator