nikobarli
Topic Author
Posts: 180
Joined: 26 Apr 2017, 06:23

CommandBinding and KeyBinding

27 Jun 2017, 09:44

Hi,

I am trying to follow the code here: https://stackoverflow.com/a/11455413/1767995, slightly modifying it to follow NoesisGUI (e.g. replacing Window element)

XAML (MyControl.xaml)
        <Grid>
            <Grid.Resources>
                <RoutedUICommand x:Key="MyCommand1" Text="Text" />
                <RoutedUICommand x:Key="MyCommand2" Text="Another Text" />
            </Grid.Resources>

            <Grid.CommandBindings>
                <CommandBinding Command="{StaticResource MyCommand1}" 
                    Executed="FirstMethod" />
                <CommandBinding Command="{StaticResource MyCommand2}" 
                    Executed="SecondMethod" />
            </Grid.CommandBindings>

            <Grid.InputBindings>
                <KeyBinding Key="Z" Modifiers="Ctrl" Command="{StaticResource MyCommand1}" />
                <KeyBinding Key="H" Modifiers="Alt" Command="{StaticResource MyCommand2}" />
            </Grid.InputBindings>

            <StackPanel>
                <Button x:Name="btn1" Command="{StaticResource MyCommand1}" Content="Click me" />
                <Button x:Name="btn2" Command="{StaticResource MyCommand2}" Content="Click me" />
            </StackPanel>
        </Grid>
C++
namespace XamlWithBlend {
    ////////////////////////////////////////////////////////////////////////////////////////////////////
    class VolumeControl : public UserControl
    {
    private:
        void InitializeComponent()
        {
            GUI::LoadComponent(this, "MyControl.xaml");
        }

    public:
        VolumeControl()
        {
            InitializeComponent();
        }

    public:
        NS_IMPLEMENT_INLINE_REFLECTION(VolumeControl, UserControl)
        {
            NsMeta<TypeId>("XamlWithBlend.VolumeControl");
        }

        void FirstMethod(BaseComponent * sender, const ExecutedRoutedEventArgs & e)
        {
            // btn1
        }

        void SecondMethod(BaseComponent * sender, const ExecutedRoutedEventArgs & e)
        {
            // btn2
        }
    };
}
Questions:
1. I couldn't find a way to register FirstMethod and SecondMethod to the reflection system. How should I do that.
2. NoesisGUI fails to load the XAML at the line: GUI::LoadComponent(this, "MyControl.xaml"); Is it because some constructs in the XAML are not supported ?
 
User avatar
sfernandez
Site Admin
Posts: 3003
Joined: 22 Dec 2011, 19:20

Re: CommandBinding and KeyBinding

30 Jun 2017, 00:40

Hi,

To connect xaml to code-behind methods you should follow the documentation about Events: http://www.noesisengine.com/docs/Gui.Co ... ind-events.

But I found a couple of bugs with the xaml you posted:
- RoutedUICommand class is not available to be used directly in the xaml.
- CommandBinding cannot use StaticResources to set the Command property.

Could you please report this sample in our bugtracker.

Thanks a lot for your feedback.
 
nikobarli
Topic Author
Posts: 180
Joined: 26 Apr 2017, 06:23

Re: CommandBinding and KeyBinding

30 Jun 2017, 02:48

Thanks. I filed the issue here: https://bugs.noesisengine.com/view.php?id=1122

Who is online

Users browsing this forum: Ahrefs [Bot] and 2 guests