Up until today I've been using MVVM Light's EventToCommand for event handling in XAML. I decided to try out InputBinding for mouse events and so far the results have been far from pleasing. I'm guessing I'm doing something wrong because there's a delay of maybe half a second between mouse clicks. With EventToCommand, the UI will update as fast as I can click it. All this test program does at the moment is fills a circle on a canvas either white or black when it's clicked.
<Canvas>
<Ellipse Canvas.Left="{Binding X}"
Canvas.Top="{Binding Y}"
Width="16"
Height="16"
Fill="Black">
<Ellipse.InputBindings>
<MouseBinding Command="{Binding RelativeSource={RelativeSource Mode=FindAncestor,
AncestorType={x:Type UserControl}},
Path=DataContext.ClickEllipse}"
CommandParameter="{Binding RelativeSource={RelativeSource Mode=FindAncestor,
AncestorType={x:Type Ellipse}}}"
MouseAction="LeftClick" />
</Ellipse.InputBindings>
public RelayCommand<object> ClickEllipse { get; set; }
ClickEllipse = new RelayCommand<object>((o) => ExecuteClickEllipse(o));
private void ExecuteClickEllipse(object o)
{
var obj = o as Ellipse;
if (obj.Fill == Brushes.Black)
{
obj.Fill = Brushes.White;
TestText = "White";
}
else
{
obj.Fill = Brushes.Black;
TestText = "Black";
}
}
What am I doing anything wrong here to cause the delay between clicks? I can't imagine that this would be the intended behavior. I have EventToCommand set up almost identically and it has no problems. Furthermore, assuming I did make a stupid mistake and this isn't intended behavior, are there any advantages of InputBinding over EventToCommand for Key and Mouse events or vice versa? How do the 2 differ in terms of functionality and performance (if that's even an issue in this situation)?
Edit - Something else I've noticed with both InputBinding and EventToCommand (which I have set up almost identically) is that each time the circle is clicked, task manager shows the program's memory usage jumping up a bit. Is this normal?