我有以下代码:
[OnTap ("Account")]
[Alignment (UITextAlignment.Center)]
[Entry ("Create ScanDo! Account")]
public string Login;
我想根据另一个字段的内容,然后在单击按钮后动态设置单元格背景颜色。任何人都可以用一些样品指出我的方向吗?
谢谢,瑞克
我有以下代码:
[OnTap ("Account")]
[Alignment (UITextAlignment.Center)]
[Entry ("Create ScanDo! Account")]
public string Login;
我想根据另一个字段的内容,然后在单击按钮后动态设置单元格背景颜色。任何人都可以用一些样品指出我的方向吗?
谢谢,瑞克
我想出的答案:
btnLogin = new StyledStringElement("", delegate {Account();})
要定义对象,请将其添加到 RootElement,然后:
btnLogin.BackgroundColor = UIColor.Green;
设置颜色!这种方法让我可以设置颜色、字体、大小和标题。
伟大的工作米格尔,谢谢!
当您将按钮添加到根集合时,您可以设置颜色。就像你设置一个部分的元素一样。
Root = new RootElement("First Section") {
new Section ("Test"){
new StyledStringElement("Login", delegate { Account(); })
{
BackgroundColor = UIColor.Green
}
}
}
我不喜欢继续拉皮条我的项目,但在这种情况下,它是你的最佳选择。
查看https://github.com/RobertKozak/MonoMobile.MVVM
我的项目一开始是为 MonoTouch.Dialog 添加数据绑定支持,但已经发展成为一个比 MonoTouch.Dialog 更易于使用的更大框架。
使用 MonoMobile.MVVM 执行您想要的代码如下所示:
public class ButtonView : View, INotifyPropertyChanged
{
private UIColor ButtonColor = UIColor.Red;
[Button]
[Bind("ButtonColor", "BackgroundColor")]
public void Test()
{
ButtonColor = UIColor.Green;
PropertyChanged(this, new PropertyChangedEventArgs("ButtonColor"));
}
public event PropertyChangedEventHandler PropertyChanged = (s,e)=>{};
}
有更好的方法可以使用适当的 ViewModel 来完成此操作,但这将按照列出的方式工作(我在此处输入之前对其进行了测试。)
MonoMobile.MVVM 仍处于测试阶段,但足以让您继续前进。在我完成实施 INotifyCollectionChanged 并为各种 Element 属性添加更多绑定后,它应该在接下来的几周内处于完全发布状态。