1

I have a window with a button in it, and I need to remove it OR not depending on the argument passed to the window:

    public MainWindow(bool removeControl)
    {
        InitializeComponent();
        if (removeControl)
        {
            //code to remove the button
        }
    }

In the XAML file I declare a normal button:

<Button Width="120" Height="25" Content="Click" Name="ClickButton"></Button>

I know this can be done by doing the reverse thing which means add the button depending of the Boolean parameter, but I need to do so.

Whymarrh
  • 13,139
  • 14
  • 57
  • 108
Redaa
  • 1,540
  • 2
  • 17
  • 28

1 Answers1

3

You can do:

mybutton.Visibility = Visibility.Collapsed;

...or if you really want it to be removed from the "logical tree"...then it all depends what "container"/parent that Button is in, in how you remove it.

Community
  • 1
  • 1
Colin Smith
  • 12,375
  • 4
  • 39
  • 47
  • Ah that's working, i tried to modify the isvisible property of the button but it doesn't work , thanks for the tiip – Redaa Aug 17 '14 at 21:22