首页 > 解决方案 > Xamarin 形式;如何从 rg.plugins 弹出页面的 xaml.cs 类访问标签?

问题描述

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

我尝试在 xaml 中为标签添加一个 id,但这是不可能的。有没有办法从 xaml.cs 类更改标签文本颜色。

提前致谢

标签: popuplabel

解决方案


一些示例代码将有助于理解问题可能是什么。我假设 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 已设置为具有公共属性或绑定属性的对象ColorThatIWantINotiftyPropertyChanged如果您希望表单对属性更改做出反应,请不要忘记实施。
  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>

推荐阅读