У меня есть класс страницы содержимого, который содержит некоторые формы. А теперь у меня есть другой класс, который должен изменить формы в классе страницы, например, изменить текст метки или обновить представление списка.
Тестовый класс:
public class testClass
{
testPage localpage;
public void changeText(string txt)
{
localpage.bPumpDrv = Convert.ToByte(txt);
localpage.testBtn.Text = txt;
}
public testClass(testPage testPagek)
{
localpage = testPagek;
}
}
Тестовая страница:
public class testPage : ContentPage, INotifyPropertyChanged
{
public byte i;
public Label testLabel;
public Button testBtn;
public byte _bPumpDrv;
public byte bPumpDrv { get { return _bPumpDrv; } set { _bPumpDrv = value; NotifyPropertyChanged("bPumpDrv"); } }
public new event PropertyChangedEventHandler PropertyChanged;
public void NotifyPropertyChanged(string info)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(info));
}
}
public testPage()
{
testClass testC = new testClass(this);
this.Title = "test";
testLabel = new Label
{
Text = "0"
};
testLabel.SetBinding(Label.TextProperty, new Binding("bPumpDrv", source: this));
testBtn = new Button
{
Text = "0"
};
testBtn.Clicked += (object sender, EventArgs e) =>
{
i += 1;
testC.changeText(i.ToString());
};
this.Content = new StackLayout
{
Children =
{
testLabel
}
};
}
}
Когда я нажимаю кнопку, метка и текст кнопки остаются неизменными, т.е. "0".
Пожалуйста, дайте мне несколько советов, спасибо!