darthmaule2
Topic Author
Posts: 98
Joined: 23 Oct 2014, 19:54

Are custom RoutedEvents supported in the Managed SDK?

15 Aug 2019, 19:11

I'm not having much luck with my custom RoutedEvents and thought I saw somewhere they were only in the native SDK...?
        public static readonly RoutedEvent TapDownEvent = EventManager.RegisterRoutedEvent(
            "TapDown", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(SBToggleButton));

        public static readonly RoutedEvent TapUpEvent = EventManager.RegisterRoutedEvent(
            "TapUp", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(SBToggleButton));
Thanks.
 
User avatar
sfernandez
Site Admin
Posts: 2995
Joined: 22 Dec 2011, 19:20

Re: Are custom RoutedEvents supported in the Managed SDK?

22 Aug 2019, 19:53

Hi, custom RoutedEvents are supported with latest 2.2.3 version of NoesisGUI C# SDK.

I just added a TapDown routed event to our Buttons sample and it is correctly firing (hover any of the buttons to set the focus there and click T key to manually fire the TapDown event):
#if NOESIS
using Noesis;
using NoesisApp;
#else
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
#endif

namespace Buttons
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            this.Initialized += OnInitialized;
            this.KeyDown += MainWindow_KeyDown;
            this.InitializeComponent();
        }

#if NOESIS
        private void InitializeComponent()
        {
            Noesis.GUI.LoadComponent(this, "MainWindow.xaml");
        }
#endif

        private void OnInitialized(object sender, EventArgs args)
        {
            this.DataContext = new ViewModel();
        }

        private void MainWindow_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.T)
            {
                RaiseTapDownEvent();
            }
        }

        #region TapDown Routed Event
        public static readonly RoutedEvent TapDownEvent = EventManager.RegisterRoutedEvent(
            "TapDown", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(MainWindow));

        public event RoutedEventHandler TapDown
        {
            add { AddHandler(TapDownEvent, value); }
            remove { RemoveHandler(TapDownEvent, value); }
        }

        /// <summary>
        /// Invoke this method when you wish to raise a(n) TapDown event
        /// </summary>
        private void RaiseTapDownEvent()
        {
            RoutedEventArgs args =
#if NOESIS
                new RoutedEventArgs(this, MainWindow.TapDownEvent);
#else
                new RoutedEventArgs(MainWindow.TapDownEvent, this);
#endif

            RaiseEvent(args);
        }
#endregion
    }
}
<Window x:Class="Buttons.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d"
        xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity" xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions"
        xmlns:noesis="clr-namespace:NoesisGUIExtensions;assembly=Noesis.GUI.Extensions"
        xmlns:local="clr-namespace:Buttons"
        Title="NoesisGUI - Buttons"
        d:DesignWidth="1280" d:DesignHeight="720">
...
    <Window.Triggers>
        <EventTrigger RoutedEvent="FrameworkElement.Loaded">
            <BeginStoryboard Storyboard="{StaticResource Intro}"/>
        </EventTrigger>
        <EventTrigger RoutedEvent="local:MainWindow.TapDown">
            <BeginStoryboard Storyboard="{StaticResource Intro}"/>
        </EventTrigger>
    </Window.Triggers>
...
</Window>
I just noticed that RoutedEventArgs constructor in Noesis has the parameters in the wrong order, we will fix that for the next release.

Who is online

Users browsing this forum: No registered users and 2 guests