Button in Shell.TitleView is not clickable

Daniel Donnelly, Jr 86 Reputation points
2023-01-09T04:53:26.24+00:00
<Shell.TitleView>  
    <StackLayout Orientation="Horizontal" Padding="0" Margin="0">  
        <Image HorizontalOptions="Start" Source="app_logo.png" WidthRequest="200"/>  
        <Label HorizontalOptions="Center" HorizontalTextAlignment="Center"  
               VerticalTextAlignment="Center" Text="Company Name" Style="{StaticResource LargeLabel}"/>  
        <Button HorizontalOptions="End" VerticalOptions="Center" Text="Sign Out" Style="{StaticResource ButtonOutline}"  
                Command="{Binding SignOutCommand}" Margin="100,0,0,0"/>  
    </StackLayout>  
</Shell.TitleView>  

There is my relevant code. The command exists and I'm importing / calling it just like any other of my buttons. Clicking does nothing. I've set a breakpoint in the SignOut command. Nothing at all. Perhaps putting everything on the actual title bar and doing the title bar properly (not some gray box - the default) would also fix this. So please help me fix either one of these issues.

Developer technologies | .NET | .NET MAUI
{count} votes

Answer accepted by question author
  1. Anonymous
    2023-01-11T05:53:18.5133333+00:00

    Hello,

    You can add BindingContext = new AppShellViewModel(); in your AppShell.xaml.cs , then when you click Sign Out button, SignOut method will be executed.

    public partial class AppShell : Shell{
     public AppShell()    {   
         
        InitializeComponent();        
        Routing.RegisterRoute("LoginPage", typeof(LoginPage));        
        BindingContext = new AppShellViewModel();        
    
    }
    
    }
    

    Best Regards,

    Leon Lu


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.