Click here to Skip to main content
15,889,462 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
this is my code

C#
private void checkBox1_Checked(object sender, RoutedEventArgs e)
  {
      if (checkBox1.IsChecked == true)
      {
          this.ShowInTaskbar = true;
      }
      else if (checkBox1.IsChecked == false)
      {
          this.ShowInTaskbar = false;

      }
System.Diagnostics.Process.Start(Application.ResourceAssembly.Location);
this.Close();


for some reason the check box doesn't check its self, and the only reason I am restarting the program is because the task bar doesn't disappear, and thats not even working, this is what is ment too happen, check box is checked, the window is seen in the task bar and when its not checked its not ment be in the task bar, can some on please help me out? everyone seems to be like bill gates on this site and can do anything.
Posted

Not true! It does work as you would expect. Your problem is: you handle Checked and do not handle Unchecked.

This is a complete solution (assuming you created a check box checkBoxShowInTaskbar in XAML):

C#
public partial class MyWindow : Window {
    public MyWindow() {
        InitializeComponent();
        checkBoxShowInTaskbar.Checked += (sender, eventArgs) =>
            { this.ShowInTaskbar = true; };
        checkBoxShowInTaskbar.Unchecked += (sender, eventArgs) =>
            { this.ShowInTaskbar = false; };
    } //MyWindow
} //class MyWindow


The solution is tested; it works.

—SA
 
Share this answer
 
v2
I believe, ShowInTaskbar must be set before the form is shown, it has no effect after a form is already shown. Restarting the program will only create a new process which which take its settings from your xaml file.

By the way, don't you think you can write your code in just one line?, like this:
C#
s.ShowInTaskbar = checkBox1.IsChecked;
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 2-Aug-11 1:44am    
Sorry, I just had to vote one this time, as you did wrong thing: posted unchecked information.

First, what you say about "after a form is already shown" is simply not true -- it does update task bar as expected during run time.

Also, assignment

s.ShowInTaskbar = checkBox1.IsChecked

will not compile! This is because IsChecked is not Boolean, it is "bool?". Remember, this is WPF, not Forms where it would work.

The OP's problem is completely different; I explained it and posted a working ***tested*** solution -- please see it.

The question is not so obvious; please understand: you really need to test solution and check up facts in such cases, to make sure what you say is true.

Thank you for understanding.
--SA
Member 7847528 17-May-14 15:09pm    
you can write it in one statement as:

this.ShowInTaskbar = checkBox1.IsChecked.Value;

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900