Пользовательские команды Prism не отображаются в xaml - PullRequest
0 голосов
/ 02 ноября 2011

У меня есть собственное определение команды в моем проекте, которое прекрасно компилируется.Когда я пытаюсь использовать его из моего представления xaml, оно не отображается.Вот кодУ меня есть ссылка на мой локальный проект в моем xaml, поэтому я не уверен, что происходит.

public class MouseDownCommandBehavior : CommandBehaviorBase<TextBox>
{
    public MouseDownCommandBehavior(TextBox element)
        : base(element)
    {
        element.MouseDown += new MouseButtonEventHandler(element_MouseDown);
    }

    private void element_MouseDown(object s, MouseEventArgs e)
    {
        base.ExecuteCommand();
    }
}
public static class MouseDown
{
    public static readonly DependencyProperty BehaviorProperty =
        DependencyProperty.RegisterAttached(
            "MouseDownCommandBehavior",
            typeof(MouseDownCommandBehavior),
            typeof(TextBox),
            null);

    public static readonly DependencyProperty CommandProperty = DependencyProperty.RegisterAttached(
        "Command",
        typeof(ICommand),
        typeof(MouseDown),
        new PropertyMetadata(OnSetCommand));

    public static readonly DependencyProperty CommandParameterProperty =
        DependencyProperty.RegisterAttached(
            "CommandParameter",
            typeof(object),
            typeof(MouseDown),
            new PropertyMetadata(OnSetParameter));

    private static void OnSetCommand(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs e)
    {
        TextBox element = dependencyObject as TextBox;
        if (element != null)
        {
            MouseDownCommandBehavior behavior = GetOrCreateBehavior(element);
            behavior.Command = e.NewValue as ICommand;
        }
    }

    private static void OnSetParameter(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs e)
    {
        TextBox element = dependencyObject as TextBox;
        if (element != null)
        {
            MouseDownCommandBehavior behavior = GetOrCreateBehavior(element);
            behavior.CommandParameter = e.NewValue;
        }
    }

    private static MouseDownCommandBehavior GetOrCreateBehavior(TextBox element)
    {
        MouseDownCommandBehavior behavior = element.GetValue(BehaviorProperty) as MouseDownCommandBehavior;
        if (behavior == null)
        {
            behavior = new MouseDownCommandBehavior(element);
            element.SetValue(BehaviorProperty, behavior);
        }

        return behavior;
    }
}

1 Ответ

0 голосов
/ 03 ноября 2011

Оказывается, мне не хватало нескольких методов: GetCommand, SetCommand, SetCommandParameter, GetCommandParameter

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