Команда Prism AttachedProperty не найдена во время выполнения - PullRequest
0 голосов
/ 03 июня 2011

Мои решения прекрасно компилируются без ошибок, но когда я запускаю свой проект Silverlight, я получаю эту ошибку: присоединяемое свойство 'Command' не найдено в типе 'TextBoxKeyUp'.В прошлом я успешно создавал поведение, и код для этого относительно тривиален.

Фрагмент XAML:

        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>

Присоединенное свойство:

    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
}

Кто-нибудь сталкивался с этой ошибкой раньше?

1 Ответ

2 голосов
/ 28 июня 2011

Я обнаружил, что мой проект оболочки не содержит ссылку на проект, в котором у меня был класс AttachedProperty. Как только я добавил ссылку, она работала как шарм.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...