【问题标题】:xamarin forms - changing button text on all carousel content pagesxamarin 表单 - 更改所有轮播内容页面上的按钮文本
【发布时间】:2018-08-30 15:12:38
【问题描述】:

执行以下操作的“最佳”(或更好)方法是什么?

在轮播页面(比如 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() 的函数,按钮文本在更改为新值之前暂时是旧值。

除此之外,我确信一定有更好的方法来做到这一点,它看起来很垃圾。

【问题讨论】:

    标签: c# android ios xamarin.forms


    【解决方案1】:

    如何为按钮创建样式,然后只更改样式的文本值?

    因此,使用绑定属性或动态资源,当您更改值时,它将更改应用程序中使用此样式的所有按钮。我认为这种方法比循环更好也更简单。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-08-13
      • 2016-10-03
      • 1970-01-01
      • 2018-03-09
      • 1970-01-01
      • 2018-03-28
      • 1970-01-01
      相关资源
      最近更新 更多