Home > Enterprise >  How to hide menu from dockpanel
How to hide menu from dockpanel

Time:01-03

I want to hide account menu in application start, after successful login want to show account menu. I tried this but it is not working, account menu is not visible.

ShellView.xaml

<Menu DockPanel.Dock="Top" FontSize="18">
        <MenuItem Header="_File">
            <MenuItem x:Name="ExitApplication" Header="E_xit" />
        </MenuItem>
        <MenuItem Header="_Account" Visibility="{Binding IsLoggedIn, Converter={StaticResource BooleanToVisibilityConverter}, FallbackValue=Collapsed}">
            <MenuItem x:Name="LogOut" Header="_Log Out" />
        </MenuItem>
    </Menu>

ShellViewModel.cs

 public bool IsLoggedIn
            {
                get
                {
                    bool output = false;
    
                    if (string.IsNullOrWhiteSpace(_user.Token) == false)
                    {
                        output = true;
                    }
    
                    return output;
                }
            }

public async Task HandleAsync(LogOnEvent message, CancellationToken cancellationToken)
        {
            await ActivateItemAsync(_salesVM);
            NotifyOfPropertyChange(() => IsLoggedIn);
        }

note: I am using visual studio 2022, .NET Framework 4.8

CodePudding user response:

when setting value of _user.token, notify that the property IsLoggedIn has changed.

  • Related