xaml 中的嵌套属性语法
我有嵌套对象,在 xaml 中定义。 例如,我有这样的代码(utils:HotkeyCommand
是代码隐藏中的 MarkupExtension 类):
<dxb:BarButtonItem>
<dxb:BarButtonItem.Command>
<utils:HotkeyCommand />
</dxb:BarButtonItem.Command>
</dxb:BarButtonItem>
它看起来相当笨拙,所以我决定按以下方式重写它(并且效果很好) ):
<dxb:BarButtonItem Command="{utils:HotkeyCommand}" />
之后,我想在我的原始代码中定义一些属性:
<dxb:BarButtonItem>
<dxb:BarButtonItem.Command>
<utils:HotkeyCommand CanExecuteNotifier="{StaticResource GeneralEnabled}" Executed="test" Gesture="Ctrl+N" />
</dxb:BarButtonItem.Command>
</dxb:BarButtonItem>
如何以相同的方式将此代码重写为一行?
我想要得到类似以下的内容(但它无法编译)。是否有任何规则可用于将一种表示法转换为第二种表示法?
<dxb:BarButtonItem Command="{utils:HotkeyCommand CanExecuteNotifier={StaticResource GeneralEnabled}, Executed={test}, Gesture={Ctrl+N}}" />
I have nested object, defined in xaml.
For example, I had a code like this (utils:HotkeyCommand
is my MarkupExtension class in code-behind):
<dxb:BarButtonItem>
<dxb:BarButtonItem.Command>
<utils:HotkeyCommand />
</dxb:BarButtonItem.Command>
</dxb:BarButtonItem>
which looked rather clumsy, so I decided to rewrite it in the following way (and this worked fine):
<dxb:BarButtonItem Command="{utils:HotkeyCommand}" />
After that, I want to define some properties in my original code:
<dxb:BarButtonItem>
<dxb:BarButtonItem.Command>
<utils:HotkeyCommand CanExecuteNotifier="{StaticResource GeneralEnabled}" Executed="test" Gesture="Ctrl+N" />
</dxb:BarButtonItem.Command>
</dxb:BarButtonItem>
How can I re-write this code to a single line in the same manner?
I want to get something like following (but it doesn't compile). Are there any rules, that can be used to transorm one notation to the second one?
<dxb:BarButtonItem Command="{utils:HotkeyCommand CanExecuteNotifier={StaticResource GeneralEnabled}, Executed={test}, Gesture={Ctrl+N}}" />
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
最后,我在 x0r 的答案的帮助下使它工作(它去了哪里?)
除了删除括号之外,我还必须更改:
Executed
从事件更改为属性持有委托Finally I made it working with the help of x0r's answer (where has it gone?)
In addition to removing brackets I also had to change:
Executed
from event to a property holding a delegate