【问题标题】:Style not supporting EventSetter xaml windows app样式不支持 EventSetter xaml Windows 应用程序
【发布时间】:2013-03-23 20:55:24
【问题描述】:

我正在尝试为 Windows 8、metro 应用程序做一个简单的计算器程序,但是当我需要为事件处理(和其他东西)做一个样式时,我得到“Windows 应用程序项目不支持 EventSetter”

<Style TargetType="Button" x:Key="my_button">
            <EventSetter Event="Click" Handler="Button_Click_1"/>
</Style>

有没有其他方法可以让我以 Metro 应用程序的风格进行事件处理?

【问题讨论】:

    标签: windows xaml microsoft-metro


    【解决方案1】:

    通常您不能在Style 中附加事件,但对于Button.Click 的具体示例,您可以使用普通的Setter 来设置Command。如果您使用 MVVM 样式的 ICommand 实现(RelayCommand、DelegateCommand 等),您可以绑定到从您的某个类公开的 ICommand 实例:

        <Style TargetType="Button" x:Key="my_button">
            <Setter Property="Command" Value="{Binding Path=MyClickCommand}"/>
        </Style>
    

    【讨论】:

    • 除了样式设置器也不支持绑定... :) 不,在这种情况下您需要附加行为! :)
    猜你喜欢
    • 1970-01-01
    • 2014-06-23
    • 1970-01-01
    • 2015-11-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-10
    相关资源
    最近更新 更多