【问题标题】:Alternate syntax in XAML for applying attached propertyXAML 中用于应用附加属性的替代语法
【发布时间】:2013-03-11 09:32:09
【问题描述】:

如何重写以下 XAML:

<Button Command="{Binding NewSalesOrderCommand}" Content="New Order" Width="50" />

这样我就可以在 Command 对象上使用附加属性:

<Button Content="New Order" Width="50">
    <Button.Command local:MyClass.MyAttachedProp="1">
        ...
    </Button.Command>
</Button>

表示代替 3 个点出现的是什么?

【问题讨论】:

    标签: wpf xaml attached-properties


    【解决方案1】:

    嗯,试试下面的

    <Button Content="New Order" Width="50">
        <Button.Command local:MyClass.MyAttachedProp="1">
            <Binding Path="NewSalesOrderCommand" />
        </Button.Command>
    </Button>
    

    欲了解更多信息,请查看here

    【讨论】:

    • 导致错误。 “无法在属性元素上设置属性。”
    • 你试过没有AttachedProperty吗?
    • 没有附加财产的作品。那么这里没有 XAML 方法来应用附加属性吗?
    • 那么让我看看AttachedProperty 的实现。也许有一个小问题。
    • @dotNET 通过思考。不,您不能以这种方式分配AttachedProperty。您只能将其分配给类的特定实例,而不能分配给属性。您可以为命令创建一个包装器,该包装器可以在 XAML 中初始化并绑定到例如NewSalesOrderCommand。但这似乎是一个巨大的开销。也许你应该重新考虑你的方法。这个AttachedProperty背后的意图是什么?
    猜你喜欢
    • 2020-01-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多