Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Behavior gets never called #12

Closed
KeKl opened this issue Sep 12, 2017 · 6 comments
Closed

Behavior gets never called #12

KeKl opened this issue Sep 12, 2017 · 6 comments
Labels

Comments

@KeKl
Copy link

KeKl commented Sep 12, 2017

Not sure if it is a avalonia or behavior Problem. I have following behavior:

public class DoubleTappedBehavior : Behavior<TreeViewItem>
{
    public static readonly AttachedProperty<ICommand> CommandProperty =
        AvaloniaProperty.RegisterAttached<DoubleTappedBehavior, TreeViewItem, ICommand>("Command", null, false, defaultBindingMode: Avalonia.Data.BindingMode.TwoWay);
    
    public static ICommand GetCommand(TreeViewItem element)
    {
        return element.GetValue(CommandProperty);
    }

    public static void SetCommand(TreeViewItem element, string value)
    {
        element.SetValue(CommandProperty, value);
    } 

    protected override void OnAttached()
    {
        base.OnAttached();
        AssociatedObject.DoubleTapped += DoubleTapped;
    }

    protected override void OnDetaching()
    {
        AssociatedObject.DoubleTapped -= DoubleTapped;
        base.OnDetaching();
    }

    private void DoubleTapped(object sender, RoutedEventArgs e)
    {
        if (Command == null)
            return;
        Command.Execute(null);
    }
}

I use it this way:

  <TreeView.Styles>
    <Style Selector="TreeViewItem">
      <Setter Property="commandBehaviors:DoubleTappedBehavior.Command"
              Value="{Binding Command}"/>
    </Style>
  </TreeView.Styles>

</TreeView>

The Get/Set Command is never get called. Also the attached method. Not sure where the problem is.

@wieslawsoltes
Copy link
Contributor

What version are you using official NuGet or nightly build?

Try using nightly version of Avalonia:
https://github.com/AvaloniaUI/Avalonia/wiki/Using-nightly-build-feed

and nightly version of AvaloniaBehaviors.:
https://github.com/wieslawsoltes/AvaloniaBehaviors#nuget

@wieslawsoltes
Copy link
Contributor

Currently you should use Avalonia version 0.5.2-build3857-alpha and AvaloniaBehaviors version 0.5.2-build470-alpha.

@KeKl
Copy link
Author

KeKl commented Sep 30, 2017

ok.

@wieslawsoltes
Copy link
Contributor

@KeKl Did you try Avalonia alpha build? Did it solve the issue?

@KeKl
Copy link
Author

KeKl commented Oct 14, 2017

Not yet. Im still on 0.4.x

@wieslawsoltes
Copy link
Contributor

@KeKl Please try version 0.6.0. Closing, please re-open if issue is present in 0.6.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants