Xamarin 形式;如何从 rg.plugins 弹出页面的 xaml.cs class 访问标签?

Xamarin forms; How to access the label from xaml.cs class of a rg.plugins pop up page?

我的 rg.plugins 弹出页面中有一个标签,我想在执行操作时更改标签的文本颜色。

我尝试为 xaml 中的标签添加一个 id,但这是不可能的。有什么办法可以改变标签文字颜色 xaml.cs class.

提前致谢

一些示例代码将有助于理解可能存在的问题。我假设 rg.plugins,你指的是:https://github.com/rotorgames/Rg.Plugins.Popup 所以我会相应地回答。

看起来 就像它采用标准 xaml 并将其显示在对话框类型弹出窗口中。您的样式选项应与其他选项相同:

  1. 直接在 xaml 中更改颜色。 <Label Text="This is some text" TextColor="Blue" />
  2. 通过绑定更改它。 TextColor="{Binding ColorThatIWant}" 其中页面的 BindingContext 已设置为具有 public 属性 或绑定 属性 为 ColorThatIWant 的对象。如果您希望表单对 属性 更改做出反应,请不要忘记实施 INotiftyPropertyChanged
  3. 在后面的代码中设置值。 MyLabel.TextColor = UIColor.Blue; 其中标签设置了名称值。 <Label x:Name="MyLabel" Text="This is some text" />
  4. 使用样式字典设置值。 <Label Text="This is some text" Style="{StaticBinding MyLabelStyle}"/> 风格为:
<Style x:Key="MyLabelStyle" TargetType="Label">
  <Setter Property="TextColor" Value="Blue" />
</Style>