我如何避免WPF绑定路径中的斜杠字符,或如何解决? [英] how do i escape a slash character in a WPF binding path, or how to work around?

查看:487
本文介绍了我如何避免WPF绑定路径中的斜杠字符,或如何解决?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习WPF,并且将数据源中的表格从每个列生成XAML的窗口中。



其中一些列的名称为导致以下情况:

 < DataGridTextColumn x:Name =_ Rev_UnitColumnBinding ={Binding Path = Rev / Unit} Header =Rev / UnitWidth =SizeToHeader/> 

这会导致列出现空白(像我一样)。

解决方案

在MSDN上有一个关于财产路径的文章,其中包含有关转义字符的部分:


内部索引器([]),插入符号字符(^)转义下一个字符。



您必须转义(使用XML实体)某些特定于XML语言定义的字符。使用&逃避角色&。使用>要退出结束标签>。



您必须对WPF XAML解析器行为特殊的字符进行转义(使用反斜杠\)处理标记扩展名。 / p>


  • 反斜杠(\)是转义字符本身。

  • 等号(=)分隔属性名称从属性值。

  • 逗号(,)分隔属性。

  • 正确的大括号(})是标记扩展名的结尾。


这里没有列出斜杠,所以我不知道反斜杠的转义是否正常,但是你可以尝试。



(你如何拥有这样的属性名称?在XML和C#中似乎是非法的) / p>

I'm just learning WPF, and I gragged a table from a datasource onto a window which generated XAML for each column.

Some of those columns had names that caused the following:

<DataGridTextColumn x:Name="_Rev_UnitColumn" Binding="{Binding Path=Rev/Unit}" Header="Rev/Unit" Width="SizeToHeader" />

This causes the column to come up blank (like me).

解决方案

On MSDN there is an article on property paths which has a section on escape characters:

Inside indexers ([ ]), the caret character (^) escapes the next character.

You must escape (using XML entities) certain characters that are special to the XML language definition. Use & to escape the character "&". Use > to escape the end tag ">".

You must escape (using backslash \) characters that are special to the WPF XAML parser behavior for processing a markup extension.

  • Backslash (\) is the escape character itself.
  • The equal sign (=) separates property name from property value.
  • Comma (,) separates properties.
  • The right curly brace (}) is the end of a markup extension.

The slash is not listed here so i do not know if the backslash escape would work, but you can try.

(How exactly do you have a property name like that? It seems to be illegal both in XML and C#)

这篇关于我如何避免WPF绑定路径中的斜杠字符,或如何解决?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆