popup - Xamarin 形式;如何从 rg.plugins 弹出页面的 xaml.cs 类访问标签?
问题描述
我的 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>
推荐阅读
- python - 如何从beautifulsoup中的span标签中获取字符串
- reactjs - How to pass the username into multi pages in reactjs
- filter - 如何过滤至少定义数量的观察值大于特定值的行?
- postgresql - JSONB fields and string keys
- javascript - Using generic array name in template
- javascript - 如何翻译坐标以获得完美匹配
- graphviz - Graphviz dot-file 疯狂边缘定位
- c - 如何在 Windows 中随时(同时)发送数据?
- python - 提取来自beautifulsoup的部分字符串
- python-2.7 - Python 2 Tornado 异步方法