我用C#.我想在Textboxes和XML数据源之间进行Twoways绑定.为了达到这个目的,我写了这个:
1 Binding source = new Binding();
2
3 // object ddd = XmlManager.Instance.CreateAttributeOrElement(XPath);
4 source.Path =
5 new PropertyPath(
6 string.Format("(XmlManager.Instance.CreateAttributeOrElement({0}))", XPath));
7 source.Mode = BindingMode.TwoWay;
8
9 UIElementos.UiTexto textoCampo = this as UIElementos.UiTexto;
10 textoCampo.elementoTexto.SetBinding(TextBox.TextProperty, source);
Run Code Online (Sandbox Code Playgroud)
哪里:
XPath = "dummyns/@totalConcept"XmlManager.Instance.CreateAttributeOrElement 在XML文档中创建属性,绑定将对TextBox进行该属性.CreateAttributeOrElement方法XMLManager返回如下:
totalConcept=""有一条注释行可以创建属性.另一种方法是将其隐含在实例化行中PropertyPath.当执行任何一种方法时,它会生成一个XML文档,如下所示:
<cna:dummyns xmlns:cna=\"http://tempuri.org/XMLSchema.xsd\" totalConcept=\"\" />
Run Code Online (Sandbox Code Playgroud)
但是当我分配一个值时Textbox,我在Output窗口中得到了这个:
System.Windows.Data Warning: 78 : BindingExpression (hash=3146959): TransferValue - got raw value {DependencyProperty.UnsetValue}
System.Windows.Data Warning: 86 : BindingExpression (hash=3146959): TransferValue - …Run Code Online (Sandbox Code Playgroud)