如何将文本框绑定到 XML 文件(带有命名空间)
我使用 C#。 我想在文本框和 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);
其中:
XPath = "dummyns/@totalConcept"
XmlManager.Instance.CreateAttributeOrElement
在 XML 文档中创建绑定的属性将对文本框执行操作。XMLManager
对象的CreateAttributeOrElement
方法返回如下内容:totalConcept=""
有一个注释行用于创建该属性。另一种方法是不要将其隐含在 PropertyPath
的实例化行中。当执行任何一种方法时,它都会生成一个如下所示的 XML 文档:
<cna:dummyns xmlns:cna=\"http://tempuri.org/XMLSchema.xsd\" totalConcept=\"\" />
但是当我为 Textbox
分配一个值时,我在输出窗口中得到以下内容:
System.Windows.Data Warning: 78 : BindingExpression (hash=3146959): TransferValue - got raw value {DependencyProperty.UnsetValue}
System.Windows.Data Warning: 86 : BindingExpression (hash=3146959): TransferValue - using fallback/default value ''
System.Windows.Data Warning: 87 : BindingExpression (hash=3146959): TransferValue - using final value ''
所以绑定不起作用... 在第 6 行中,我也尝试过:
string.Format("XmlManager.Instancia.declaracion.Root.Attribute[\"{0}\"].Value", XPath)
但得到了相同的结果。
有人有类似的工作吗?
欢迎任何意见或建议。
I use C#.
I want to make a Twoways bind between Textboxes and an XML data source. In order to achieve that, I have written this:
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);
Where:
XPath = "dummyns/@totalConcept"
XmlManager.Instance.CreateAttributeOrElement
creates the attribute in the XML Document which the bind will to do to TextBoxes.- The
CreateAttributeOrElement
method of theXMLManager
object returns some like this:totalConcept=""
There is a commented line which creates the attribute. The other way is ot make it implicit in the instantiation line of PropertyPath
. When either of the ways is executed, it generates an XML Document like this:
<cna:dummyns xmlns:cna=\"http://tempuri.org/XMLSchema.xsd\" totalConcept=\"\" />
But when I assign a value to Textbox
, I get this in the Output window:
System.Windows.Data Warning: 78 : BindingExpression (hash=3146959): TransferValue - got raw value {DependencyProperty.UnsetValue}
System.Windows.Data Warning: 86 : BindingExpression (hash=3146959): TransferValue - using fallback/default value ''
System.Windows.Data Warning: 87 : BindingExpression (hash=3146959): TransferValue - using final value ''
So the Bind is not working...
In the line #6, I also tried:
string.Format("XmlManager.Instancia.declaracion.Root.Attribute[\"{0}\"].Value", XPath)
But I got the same result.
Has anybody got something similar to this working?
Any comments or suggestions are welcome.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你尝试过这样的事情吗?
Have you tried something like this ?