You can use an interactivity trigger reacting to MouseRightButtonDown:
<Button>
<i:Interaction.Triggers>
<i:EventTrigger EventName="MouseRightButtonDown">
<i:InvokeCommandAction Command="{Binding command}" CommandParameter="{Binding param}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</Button>
Found this thread looking for a solution, here was my initial xaml that worked only for left click:
[code]
<Button DataContext="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type UserControl}}}" Content="" Background="#00DDDDDD" Grid.ColumnSpan="2" Margin="-5,-5,-5,-5" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" BorderBrush="#FF707070" Panel.ZIndex="1" Command="{Binding RouteOnClicked}" CommandParameter="{Binding DataContext}"/>
Then I needed double click support, so had to switch to this, which works in Blend / without Noesis, but doesn't work in Noesis:
<Button DataContext="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type UserControl}}}" Content="" Background="#00DDDDDD" Grid.ColumnSpan="2" Margin="-5,-5,-5,-5" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" BorderBrush="#FF707070" Panel.ZIndex="1">
<Button.InputBindings>
<MouseBinding Gesture="LeftClick" Command="{Binding RouteOnClicked}" CommandParameter="{Binding DataContext}"></MouseBinding>
<MouseBinding Gesture="LeftDoubleClick" Command="{Binding RouteOnDoubleClicked}" CommandParameter="{Binding DataContext}"></MouseBinding>
</Button.InputBindings>
</Button>
I tried to update it to use your suggestion (simplifying to just single left click for now):
<Button DataContext="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type UserControl}}}" Content="" Background="#00DDDDDD" Grid.ColumnSpan="2" Margin="-5,-5,-5,-5" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" BorderBrush="#FF707070" Panel.ZIndex="1">
<i:Interaction.Triggers>
<i:EventTrigger EventName="MouseLeftButtonDown">
<i:InvokeCommandAction Command="{Binding RouteOnClicked}" CommandParameter="{Binding DataContext}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</Button>
But now it doesn't work at all. This is the view in C++:
class ShipListEntryView : public Noesis::UserControl
{
public:
ShipListEntryView()
{
InitializeComponent();
}
void InitializeComponent()
{
Noesis::GUI::LoadComponent(this, "Controls/ShipListEntryView.xaml");
}
bool ConnectEvent(BaseComponent* source, const char* event, const char* handler) override
{
NS_CONNECT_EVENT(Noesis::Button, Click, OnClicked);
return false;
}
void OnClicked(Noesis::BaseComponent* sender, const Noesis::RoutedEventArgs& e)
{
Noesis::Ptr<NoesisApp::DelegateCommand> onSelectedProperty = GetValue<Noesis::Ptr<NoesisApp::DelegateCommand>>(OnSelectedProperty_);
onSelectedProperty->Execute(sender);
}
private:
inline static const Noesis::DependencyProperty* OnSelectedProperty_;
inline static const Noesis::DependencyProperty* OnFocusedProperty_;
NS_IMPLEMENT_INLINE_REFLECTION(ShipListEntryView, UserControl, "rtg.Controls.ShipListEntryView")
{
Noesis::DependencyData* data = NsMeta<Noesis::DependencyData>(Noesis::TypeOf<ShipListEntryView>());
data->RegisterProperty<Noesis::Ptr<NoesisApp::DelegateCommand>>(OnSelectedProperty_, "RouteOnClicked",
Noesis::PropertyMetadata::Create(Noesis::DependencyProperty::GetUnsetValue()));
}
};
Some questions;
1. Why can't I use MouseBinding?
2. How should I make my xaml work in both Blend and Noesis runtime / in-game? Blend doesn't like the triggers and I need that to have a workflow.
3. Where can I find a list of trigger names? E.g. "MouseLeftButtonDown". Not sure what to use for double-clicking.
4. What am I missing in the above code?