C# 根据应用程序身份验证更改母版页项目标签

C# 根据应用程序身份验证更改母版页项目标签,c#,xamarin.forms,C#,Xamarin.forms,在我的xamarin表单应用程序中,我希望在用户未登录时母版页上有一个按钮显示“登录”。一旦用户登录,我希望相同的按钮说“注销” 我使用INotifyPropertyChanged创建了一个masterpageitem类。 我已经创建了一个ObservableCollection masterPageItems。 我有listView.ItemsSource=App.masterPageItems //masterpageitem.cs public class MasterPageItem :

在我的xamarin表单应用程序中,我希望在用户未登录时母版页上有一个按钮显示“登录”。一旦用户登录,我希望相同的按钮说“注销”

我使用INotifyPropertyChanged创建了一个masterpageitem类。 我已经创建了一个ObservableCollection masterPageItems。 我有listView.ItemsSource=App.masterPageItems

//masterpageitem.cs

public class MasterPageItem : INotifyPropertyChanged
{
    private string title;
    public string Title
    {
        get
        {
            return title;
        }
        set
        {
            title = value;
            NotifyPropertyChanged("title");
        }
    }

    public string IconSource { get; set; }

    public Type TargetType { get; set; }

    public event PropertyChangedEventHandler PropertyChanged;
    private void NotifyPropertyChanged(string info)
    {
        PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(info));
    }
}
//App.xaml.cs

public static ObservableCollection<MasterPageItem> masterPageItems = new ObservableCollection<MasterPageItem>
        {
            new MasterPageItem
            {
                Title = "Home",
                IconSource = "home.png",
                TargetType = typeof(HomePage)
            },
            new MasterPageItem
            {
                Title = "Competitions",
                IconSource = "logo.png",
                TargetType = typeof(Views.PlayerTournaments)
            },
            new MasterPageItem
            {
                Title = App.authenticated?"Sign out":"Sign in",
                IconSource = "logo.png",
                TargetType = typeof(LoginPage)
            }
        };
//Masterpage.xaml

<ListView x:Name="listView">
        <ListView.ItemTemplate>
            <DataTemplate>
                <ViewCell>
                    <Grid Padding="5,10">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="30"/>
                            <ColumnDefinition Width="*" />
                        </Grid.ColumnDefinitions>
                        <Image Source="{Binding IconSource}" />
                        <Label Grid.Column="1" Text="{Binding Title}" />
                    </Grid>
                </ViewCell>
            </DataTemplate>
        </ListView.ItemTemplate>
    </ListView>

当我注销时-当我希望母版页项目显示“登录”时,母版页项目仍为“注销”

NotifyPropertyChanged(“标题”)-您的财产是大写字母T“Title”而不是“Title”,谢谢。现在工作正常了。
<ListView x:Name="listView">
        <ListView.ItemTemplate>
            <DataTemplate>
                <ViewCell>
                    <Grid Padding="5,10">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="30"/>
                            <ColumnDefinition Width="*" />
                        </Grid.ColumnDefinitions>
                        <Image Source="{Binding IconSource}" />
                        <Label Grid.Column="1" Text="{Binding Title}" />
                    </Grid>
                </ViewCell>
            </DataTemplate>
        </ListView.ItemTemplate>
    </ListView>
void UpdateSignInState(UserContext userContext)
    {
        var isSignedIn = userContext.IsLoggedOn;
        btnSignInSignOut.Text = isSignedIn ? "Sign out" : "Sign in";
        App.authenticated = isSignedIn;
        App.masterPageItems[2].Title = App.authenticated ? "Sign out" : "Sign in";
    }