Navigate Behavior

Topics: Feature requests
Sep 29, 2012 at 10:23 AM

Hi Geert,

how about adding the following WPF Navigation Behavior for Hyperlinks because they only work correctly in pages:

   public class Navigate : Behavior<Hyperlink>
    {
        protected override void OnAttached()
        {
            base.OnAttached();
            this.AssociatedObject.RequestNavigate += this.AssociatedObjectRequestNavigate;
        }

        protected override void OnDetaching()
        {
            this.AssociatedObject.RequestNavigate -= this.AssociatedObjectRequestNavigate;
            base.OnDetaching();
        }

        private void AssociatedObjectRequestNavigate(object sender, RequestNavigateEventArgs e)
        {
            var uri = this.AssociatedObject.NavigateUri;

            if (uri != null)
            {
                   ServiceLocator.Instance.GetInstance<IProcessService>().StartProcess(uri.ToString());
            }
        }
    }

Usage:

<TextBlock>
   <Hyperlink NavigateUri="http://catel.codeplex.com">
       <i:Interaction.Behaviors>
            <catel:Navigate />
       </i:Interaction.Behaviors>

       <TextBlock Text="The best MVVM Framework" />
    </Hyperlink>
</TextBlock>

Many Thanks!



 

Coordinator
Sep 29, 2012 at 10:38 AM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.