Christian Russo Christian Russo - 1 year ago 122
C# Question

TaskbarIcon wpf error in C#

I am doing a MenuItem with TaskbarIcon, and I need some item enable and some disable. So I do this:

<MenuItem Header="Open" Visibility="true"/>
<MenuItem Header="Settings" Visibility="true"/>
<MenuItem Header="Close" Visibility="true"/>

<MenuItem Header="Desconnect" Visibility="false" />
<MenuItem Header="Show status" Visibility="false" />
<MenuItem Header="Show logs" Visibility="false" />
<MenuItem Header="Show servers" Visibility="false" />
<MenuItem Header="Settings" Visibility="false" />
<MenuItem Header="Close" Visibility="false" />

But I obtain a wrong menu, like this picture: picture

How can I resolve this problem?


Answer Source

Visibility is not a flag based dependency property. It contains three available (enum) choises Visible, Collapsed and Hidden. To fix issue you're having you should use Collapsed.

Hidden just hides control which is marked with this property, but size that it occupy is still presisted. That is the reason you are experiencing issue shown in the picture.

Collapsed you can call it removes item your view completely without any visible trace.

For more information refer here.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download