Silverlight 在运行时未找到Prism AttachedProperty命令
我的解决方案编译得很好,没有错误,但是当我运行Silverlight项目时,我得到了这个错误:在类型“TextBoxKeyUp”中找不到可附加属性“Command”。我在过去成功地创建了一些行为,而这个行为的代码相对来说是微不足道的 XAML代码段:Silverlight 在运行时未找到Prism AttachedProperty命令,silverlight,prism,Silverlight,Prism,我的解决方案编译得很好,没有错误,但是当我运行Silverlight项目时,我得到了这个错误:在类型“TextBoxKeyUp”中找不到可附加属性“Command”。我在过去成功地创建了一些行为,而这个行为的代码相对来说是微不足道的 XAML代码段: xmlns:prismCmd="clr-namespace:AGMGUI.Infrastructure.AttachedProperty;assembly=AGMGUI.Infrastructure" &l
xmlns:prismCmd="clr-namespace:AGMGUI.Infrastructure.AttachedProperty;assembly=AGMGUI.Infrastructure"
<TextBox Grid.Column="2" Text="{Binding InputFieldText, Mode=TwoWay}"
TabIndex="1" Width="100" Height="24" HorizontalAlignment="Left"
VerticalAlignment="Center" prismCmd:TextBoxKeyUp.Command="{Binding KeyUpCommand}"></TextBox>
以前有人遇到过这个错误吗?我发现我的shell项目没有包含对我拥有AttachedProperty类的项目的引用。一旦我添加了引用,它就像一个符咒 作为测试,尝试将“Command”重命名为“MyCommand”。我暗自怀疑,命令可能被保留了。
public static class TextBoxKeyUp
{
#region Command attached property
public static ICommand GetCommand(DependencyObject obj)
{
return (ICommand)obj.GetValue(CommandProperty);
}
public static void SetCommand(DependencyObject obj, ICommand value)
{
obj.SetValue(CommandProperty, value);
}
// Using a DependencyProperty as the backing store for Command. This enables animation, styling, binding, etc...
public static readonly DependencyProperty CommandProperty =
DependencyProperty.RegisterAttached("Command", typeof(ICommand), typeof(TextBoxKeyUp), new PropertyMetadata(OnSetCommandCallback));
private static void OnSetCommandCallback(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs e)
{
TextBox element = dependencyObject as TextBox;
if (element != null)
{
TextBoxKeyUpBehavior behavior = GetOrCreateBehavior(element);
behavior.Command = e.NewValue as ICommand;
}
}
private static TextBoxKeyUpBehavior GetOrCreateBehavior(TextBox element)
{
TextBoxKeyUpBehavior behavior = element.GetValue(KeyUpBehaviorProperty) as TextBoxKeyUpBehavior;
if (behavior == null)
{
behavior = new TextBoxKeyUpBehavior(element);
element.SetValue(KeyUpBehaviorProperty, behavior);
}
return behavior;
}
#endregion
#region KeyUpBehavior attached property
public static TextBoxKeyUpBehavior GetKeyUpBehavior(DependencyObject obj)
{
return (TextBoxKeyUpBehavior)obj.GetValue(KeyUpBehaviorProperty);
}
public static void SetKeyUpBehavior(DependencyObject obj, TextBoxKeyUpBehavior value)
{
obj.SetValue(KeyUpBehaviorProperty, value);
}
public static readonly DependencyProperty KeyUpBehaviorProperty =
DependencyProperty.RegisterAttached("KeyUpBehavior", typeof(TextBoxKeyUpBehavior), typeof(TextBoxKeyUp), null);
#endregion
#region CommandParameter attached property
public static object GetCommandParameter(DependencyObject obj)
{
return (object)obj.GetValue(CommandParameterProperty);
}
public static void SetCommandParameter(DependencyObject obj, object value)
{
obj.SetValue(CommandParameterProperty, value);
}
public static readonly DependencyProperty CommandParameterProperty =
DependencyProperty.RegisterAttached("CommandParameter", typeof(object), typeof(TextBoxKeyUp), new PropertyMetadata(OnSetCommandParameterCallback));
private static void OnSetCommandParameterCallback(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs e)
{
TextBox element = dependencyObject as TextBox;
if (element != null)
{
TextBoxKeyUpBehavior behavior = GetOrCreateBehavior(element);
behavior.CommandParameter = e.NewValue;
}
}
#endregion
}