- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
一段时间以来,我一直在努力寻找解决方案,并且可以提供一些帮助。我知道我以前见过这样的例子,但今晚我找不到任何接近我需要的东西。
我有一项服务可以为我提供所有 DropDownLists,无论是来自缓存还是来自 DomainService。它们以 IEnumerable 的形式呈现,并使用 GetLookup(LookupId) 从存储库中请求。
我创建了一个自定义属性,我装饰了我的 MetaDataClass,它看起来像这样:
[Lookup(Lookup.Products)]
public Guid ProductId
public class CustomDataForm : DataForm
{
private Dictionary<string, DataField> fields = new Dictionary<string, DataField>();
public Dictionary<string, DataField> Fields
{
get { return this.fields; }
}
protected override void OnAutoGeneratingField(DataFormAutoGeneratingFieldEventArgs e)
{
PropertyInfo propertyInfo = this.CurrentItem.GetType().GetProperty(e.PropertyName);
foreach (Attribute attribute in propertyInfo.GetCustomAttributes(true))
{
LookupFieldAttribute lookupFieldAttribute = attribute as LookupFieldAttribute;
if (lookupFieldAttribute != null)
{
// Create a combo box.
// Bind it to my Lookup IEnumerable
// Set the selected item to my Field's Value
// Set the binding two way
}
}
this.fields[e.PropertyName] = e.Field;
base.OnAutoGeneratingField(e);
}
}
if (lookupFieldAttribute != null)
{
ComboBox comboBox = new ComboBox();
Binding newBinding = e.Field.Content.GetBindingExpression(TextBox.TextProperty).ParentBinding.CreateCopy();
newBinding.Mode = BindingMode.TwoWay;
newBinding.Converter = new LookupConverter(lookupRepository);
newBinding.ConverterParameter = lookupFieldAttribute.Lookup.ToString();
comboBox.SetBinding(ComboBox.SelectedItemProperty,newBinding);
comboBox.ItemsSource = lookupRepository.GetLookup(lookupFieldAttribute.Lookup);
e.Field.Content = comboBox;
}
最佳答案
我找到了解决方案。
if (lookupFieldAttribute != null)
{
ComboBox comboBox = new ComboBox();
Binding newBinding = e.Field.Content.GetBindingExpression(TextBox.TextProperty).ParentBinding.CreateCopy();
var itemsSource = lookupRepository.GetLookup(lookupFieldAttribute.Lookup);
var itemsSourceBinding = new Binding { Source = itemsSource };
comboBox.SetBinding(ItemsControl.ItemsSourceProperty, itemsSourceBinding);
newBinding.Mode = BindingMode.TwoWay;
newBinding.Converter = new LookupConverter(lookupRepository);
newBinding.ConverterParameter = lookupFieldAttribute.Lookup.ToString();
comboBox.SetBinding(ComboBox.SelectedItemProperty,newBinding);
e.Field.Content = comboBox;
}
关于silverlight-4.0 - Silverlight 4 覆盖 DataForm Autogenerate 以插入绑定(bind)到转换器的组合框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2557951/
我正在使用 ASMX 进行服务的 Silverlight 4 + MVVM 项目。 我正在寻找 DataForm要麻烦。 IEditableObject ,绑定(bind)等似乎很痛苦。我在没有 Da
使用 DataForm 对象,我发现它可以正确地将值发布到服务器。这是截图 但是在服务器上我得到的这些对象为空。这是我的服务器端代码 @RequestMapping(method = POST
我有一个带有 AutoCommit = "False"的 DataForm 和一个绑定(bind)到命令 SaveCommand 的外部保存按钮。 如果我希望在未对数据(我使用 ViewModel)进
我想知道你是怎么做这样的事情的。假设,我们有修改树(例如菜单结构)的 MVVM CRUD 应用程序。我们有一个带有菜单项的 View 模型和两个 View :第一个带有 TreeView第二个是 Da
我正在将 DataForm 用于具有大约 40 个属性的实体。我对表单显示除 3 个属性之外的所有属性的方式感到满意。这 3 个属性恰好是项目列表。 我不想编写整个编辑模板的代码,这似乎非常适得其反。
有人可以帮忙吗? 我有这个一页应用程序来显示问题: 如果您修改字段,然后按顶部的“保存”,则更改后的字段不会显示在控制台上...
有人可以帮忙吗? 我有这个一页应用程序来显示问题: 如果您修改字段,然后按顶部的“保存”,则更改后的字段不会显示在控制台上...
我正在尝试处理来自 datafrom 外部的内部添加/删除/编辑命令表单按钮控件的数据。我正在使用 MVVMLight。例如:要在删除按钮 EventToCommand 中删除,我 Bind Comm
我有一个小的 DataForm,我想将焦点设置在第一个 TextBox 上。我正在使用 2009 年 11 月的工具包。我已经命名了 TextBox 并尝试使用 DataForm 的加载事件中的 .F
是否有一种惯用的方式来指示此模型中的字段应该是密码文本框: public class User { [Required] public string Username { get; set
我有这个代码,当您输入 ID 并按搜索时,它会正确显示数据。但是如果你想通过姓氏和身份证来寻找,它不会带来任何东西。我认为我做错了 else if 语句,但还找不到错误。 Private Sub cm
这是我的布局:
我正在寻找像 DataForm 这样的控件,它是 Silverlight 3 中的新控件,用于处理 WPF 的整个绑定(bind)和验证逻辑(声明式地使用属性属性等)。 我一直认为 SL 是 WPF
我试图理解 DataForm 在 2009 年 11 月的工具包中实现,但我不知道如何将 ComboBox 绑定(bind)到枚举。有谁知道 DataForm 是如何自动执行此操作的? 背景 首先,我
我有一个DataForm,它已设置要折叠的某些DataField的可见性,并且当用户从ComboBox选择一个选项时,应再次使某些DataField可见。 基本上(用粗略的伪代码)。 OnComboB
晚上好, 我正在寻找帮助我了解如何将 Silverlight DataForm 与使用 WCF Ria 服务的 ViewModel 结合的人。我想要完成的是使用 DataForm 管理我的实体集合并利
在 silverlight 2 中,可以通过 DataGrid 将新行添加到集合中。但在 silverlight 3 中,我不知道如何在不使用 DataForm 的情况下做到这一点。有什么想法吗? 最
我有一个绑定(bind)到一个对象的数据表单,该对象的属性用 System.ObjectModel.DataAnnotation 装饰。验证的属性。 我面临的问题是这个类的某些属性只是有条件地需要,不
我有几个组合框 在数据表单中 并试图让它禁用某些组合框,直到选择特定的组合框。为此,我创建了一个名为 CanEditCombo 的通知属性。在绑定(bind)到 DataContext 并像这样配置我
我有主/详细信息 - 数据网格/数据表单,在选择项目后它显示在数据表单中以进行更新,但我在数据绑定(bind)或用部门填充组合框并将 SelectedEmployee.departmentid 设置为
我是一名优秀的程序员,十分优秀!