當我單擊按鈕時,它會被隱藏,但是當我重繪 頁面時它仍然存在。如何根據標簽中的內容使其保持隱藏狀態?
private void Button3_Clicked(object sender, EventArgs e)
{
App.products[Index].Quantity ;
Button btn = (Button)sender;
if (btn.IsVisible)
{ btn.IsVisible = false; }
else
{
btn.IsVisible = false;
}
}
我希望此 Button 在重繪 頁面時根據此值App.products[Index].Quantity保持隱藏狀態。當我單擊按鈕時,它會從 0 變為 1,如果它不是 0,我希望隱藏按鈕。
uj5u.com熱心網友回復:
在 YourPage.xaml 中:
<Button IsVisible={Binding ButtonIsVisible} ... />
在 YourPage.xaml.cs 中:
public YourPage()
{
InitializeComponent();
...
BindingContext = this;
}
// NOTE: `=>` not `=`. To be a property; expression evaluated every time it is needed.
public bool ButtonIsVisible => App.products[Index].Quantity == 0;
private void Button3_Clicked(object sender, EventArgs e)
{
App.products[Index].Quantity ;
// So xaml sees the change.
OnPropertyChanged(nameof(ButtonIsVisible));
}
欲了解更多資訊,谷歌xamarin binding。
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/480351.html
標籤:C# xamarin 按钮 xamarin.android 显示隐藏
下一篇:XamarinSystem.NullReferenceException:“物件參考未設定為物件的實體。”當我嘗試使用ApiRest時出現
