[英]How to prevent all buttons text in a listview from changing xamarin forms
[英]xamarin forms - changing button text on all carousel content pages
做以下事情的“最佳”(或更好)方法是什么?
在輪播頁面(例如6個內容頁面)中,我單擊一個按鈕,部分操作會更改該按鈕上的文本,但對於所有其他內容頁面也必須更改。
我目前在輪播頁面OnCurrentPageChanged()中發生這種情況,我在其中調用一個函數並傳遞“ this”。 helpers.ChangeAll(this);
public void ChangeAll(CarouselSwipePage page)
{
foreach (SwipePageContent v in page.Children)
{
Button b = v.Content.FindByName<Button>("pause");
if (GlobalSettings.Settings.Default.CarouselCountEnabled) //this is set elsewhere and is used to determine whether the carousel is changing automatically, if it is then set the text to pause
{
b.Text = FontAwesomeFont.PauseCircleO;
}
else
{
b.Text = FontAwesomeFont.PlayCircleO;
}
}
}
這在android上可以正常運行,但在ios上,當用戶單擊按鈕后滑動到下一個內容頁面時,由於該函數稱為OnCurrentPageChanged(),因此按鈕文本在更改為新值之前暫時是舊值。
除此之外,我確信必須有更好的方法來完成此任務,它看起來很垃圾。
如何為按鈕創建樣式,然后僅更改樣式的文本值呢?
因此,使用綁定屬性或動態資源,當您更改值時,它將更改應用程序中使用此樣式的所有按鈕。 我認為這種方法比循環好得多,也更簡單。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.