CommandBinding and KeyBinding
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)
C++
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 ?
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)
Code: Select all
<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>
Code: Select all
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
}
};
}
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 ?
-
sfernandez
Site Admin
- Posts: 3003
- Joined:
Re: CommandBinding and KeyBinding
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.
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.
Re: CommandBinding and KeyBinding
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