在运行时更改 Silverlight DataForm:DataField 标签值
我有一个数据表单,它绑定到 Silverlight 应用程序中视图模型中的属性,我已经使用 WCF RIA 服务创建了实体类,并且每个属性都有 DisplayName 属性,该属性显示在数据表单数据字段标签中。我需要做的是在我创建的自定义数据字段中每个标签的末尾添加一个“:”。 我需要这种情况发生的原因是因为我的页面中有一个网格,它绑定到当前对象(例如员工)的列表,并且我不希望网格标题末尾有“:”,但我也需要“:”当我尝试编辑或添加新员工时。
这就是我到目前为止所做的,但它不起作用。
public class CustomDataField : DataField
{
public CustomDataField()
{
}
public new object Label
{
get { return base.Label; }
set
{
base.Label = value;
if( value is string )
{
base.Label = (string)value + ":";
}
}
}
}
I'm having a dataform which is binded to a property in my view-model in a Silverlight application, I've created my entity classes with WCF RIA Services and every property has the attribute of DisplayName which is shown in the dataform datafield label. what I need to do is to add a ":" at the end of every label in the custom datafields that I create.
The reason I need this to happen is because I have a grid in my page which is binded to the list of current objects (e.g. Employees) and I don't want ":" at the end of the grid headers, but I also need ":" when I'm trying to edit or add a new employee.
This is what I've done so far, but it's not working.
public class CustomDataField : DataField
{
public CustomDataField()
{
}
public new object Label
{
get { return base.Label; }
set
{
base.Label = value;
if( value is string )
{
base.Label = (string)value + ":";
}
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
(1)
当您不让 DataForm 自动生成字段时,您可以更好地控制字段并可以手动设置标签:
(2)
如果您需要自动生成功能,但还需要更多地控制字段的生成方式显示后,您可以将 DataForm 包装到您自己的自定义控件中。您必须自己实现自动生成来构建您自己的 EditTemplate,并将其分配给 DataForm。这是我走过的路。
(3)
另一种快速但肮脏的方法是在 DataForm 呈现后迭代可视化树以更改标签。在工具包的帮助下,这一切变得非常简单:
(4)
最后,我刚刚看到 DataForm 上有一个可以工作的 AutoGenerateField 事件(未经测试):
(1)
When you don't let the DataForm autogenerate the fields, you have more control over the fields and can set the labels manually:
(2)
If you need the auto-generating functionality, but you also need more control over how fields are displayed, you could wrap the DataForm into your own custom control. You'll have to implement the auto-generation yourself to build your own EditTemplate, which you'd assign to the DataForm. This is the road that I took.
(3)
Another quick and dirty way would be to iterate through the visual tree after the DataForm has rendered to change the labels. That goes pretty straightforward with a little help from the toolkit:
(4)
Finally, I just saw that there is an AutoGeneratingField event on the DataForm that could work (untested):