>我的rg.plugins弹出页面中有一个标签,我想在执行操作时更改标签的文本颜色。
我尝试在 xaml 中向标签添加 id,但这是不可能的。有没有办法从 xaml.cs 类更改标签文本颜色。
提前致谢
一些示例代码将有助于了解问题可能是什么。我假设通过 rg.plugins,你指的是:https://github.com/rotorgames/Rg.Plugins.Popup 所以我会相应地回答。
看起来它采用标准 xaml 并将其显示在对话框类型弹出窗口中。样式选项应与其他任何选项相同:
- 直接在 xaml 中更改颜色。
<Label Text="This is some text" TextColor="Blue" />
- 通过绑定更改它。
TextColor="{Binding ColorThatIWant}"
页面的 BindingContext 已设置为具有ColorThatIWant
的公共属性或绑定属性的对象。如果您希望表单对属性更改做出反应,请不要忘记实现INotiftyPropertyChanged
。 - 在代码隐藏中设置值。 标签设置了名称值的
MyLabel.TextColor = UIColor.Blue;
。<Label x:Name="MyLabel" Text="This is some text" />
- 使用样式字典设置值。
<Label Text="This is some text" Style="{StaticBinding MyLabelStyle}"/>
风格为:
<Style x:Key="MyLabelStyle" TargetType="Label">
<Setter Property="TextColor" Value="Blue" />
</Style>