【发布时间】:2011-01-19 21:11:25
【问题描述】:
我有(注意Extras.WP7):
<phone:PhoneApplicationPage
xmlns:cmd="clr-namespace:GalaSoft.MvvmLight.Command;assembly=GalaSoft.MvvmLight.Extras.WP7"
>
...它在我的 EventToCommand 中运行良好,如下所示:
<phone:PhoneApplicationPage.Resources>
<i:EventTrigger x:Key="KeyPadButtonTrigger" EventName="Click">
<cmd:EventToCommand Command="{Binding Path=KeyPadButtonCommand}" CommandParameter="{Binding ElementName=Self, Path=Content }" />
</i:EventTrigger>
</phone:PhoneApplicationPage.Resources>
但后来我想像这样使用 MmvmLight 的ButtonBaseExtensions:
<Button x:Name="button1"
cmd:ButtonBaseExtensions.Command="{Binding KeyPadButtonCommand}"
cmd:ButtonBaseExtensions.CommandParameter="{Binding ElementName=button1, Path=Content }"/>
...但是当我这样做时,我得到了"The attachable property 'Command' was not found in type 'ButtonBaseExtensions'" 错误。
我发现我还必须为 assembly=GalaSoft.MvvmLight.WP7 添加一个命名空间,如下所示:
<phone:PhoneApplicationPage
xmlns:cmdxtras="clr-namespace:GalaSoft.MvvmLight.Command;assembly=GalaSoft.MvvmLight.Extras.WP7"
xmlns:cmd="clr-namespace:GalaSoft.MvvmLight.Command;assembly=GalaSoft.MvvmLight.WP7"
>
请注意,我同时拥有 xmlns:cmdxtras 和 xmlns:cmd。如果我只有一个或另一个,事情就行不通!
这看起来很笨拙,与我认为其他人的建议不符。为什么我都需要?
【问题讨论】:
标签: silverlight xaml windows-phone-7 mvvm-light