xaml 中的嵌套属性语法

发布于 2024-12-13 08:58:35 字数 967 浏览 0 评论 0原文

我有嵌套对象,在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

本王不退位尔等都是臣 2024-12-20 08:58:35

最后,我在 x0r 的答案的帮助下使它工作(它去了哪里?)

 <dxb:BarButtonItem Command="{utils:HotkeyCommand {StaticResource GeneralEnabled}, Executed=test, Gesture=Ctrl+N}" />

除了删除括号之外,我还必须更改:

  1. Executed 从事件更改为属性持有委托
  2. 为了能够从资源使用 HotkeyCommand,我必须在 MarkupExtension 中使用参数创建一个构造函数,如下所述 此处

Finally I made it working with the help of x0r's answer (where has it gone?)

 <dxb:BarButtonItem Command="{utils:HotkeyCommand {StaticResource GeneralEnabled}, Executed=test, Gesture=Ctrl+N}" />

In addition to removing brackets I also had to change:

  1. Change Executed from event to a property holding a delegate
  2. To make possible using HotkeyCommand from a resource, I had to create a constructor in MarkupExtension with a parameter, as described here
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文