Xamarin标签IsVisible Propety不变

时间:2018-11-22 12:09:43

标签: c# xamarin xamarin.forms binding viewmodel

我有一个弹出页面,在此弹出页面中,我有一个带有IsVisible属性的Label绑定到我的ViewModel。但是,当IsVisible属性更改时,站点不会刷新。我的代码有什么问题?

我的Xaml

 <StackLayout>
        <Label Text="Name der Einkaufsliste" />
        <Entry x:Name="entryList" FontSize="20"
               Placeholder="z.B. Lidl" />
        <Label Text="Liste schon Vorhanden!" TextColor="Red" IsVisible="{Binding IsVisible, Mode=TwoWay}"/>
    </StackLayout>

我的xaml.cs

PopupViewModel vm = new PopupViewModel();
    public PopupViewListeHinzufügen()
    {
        InitializeComponent();
        BindingContext = vm;
    }

    private void Button_Clicked(object sender, EventArgs e)
    {
        MasterPage master = new MasterPage();
        master.addList(entryList.Text);
    }

    public void ListeVorhandenMeldung()
    {
        vm.setLabelVisible();
    }

我的视图模型:

public class PopupViewModel : INotifyPropertyChanged
{
    public event PropertyChangedEventHandler PropertyChanged;

    public PopupViewModel()
    {
        IsVisible = false;
    }

    public void OnPropertyChanged([CallerMemberName] string propertyName = null)
    {
        PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
    }

    public void setLabelVisible()
    {
        IsVisible = true;
    }

    private bool isVisible;

    public bool IsVisible
    {
        get
        {
            return isVisible;
        }
        set
        {
            isVisible = value;
            OnPropertyChanged("IsVisible");
        }
    }
}

感谢您的帮助!

0 个答案:

没有答案