Hi all I am trying to implement an on click effect in the items of a listbox but I keep getting this error:
The type 'cmd:EventToCommand' was not found. Verify that you are not missing an assembly reference and that all referenced assemblies have been built.
<catel:UserControl
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:catel="http://catel.codeplex.com"
xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
xmlns:cmd="http://www.galasoft.ch/mvvmlight"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
And the code where I try to implement the on click method:
<Grid>
<ItemsControl ItemsSource="{Binding Source={StaticResource cvsRoutes}}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Expander Header="{Binding Name}" MinHeight="50">
<ListBox>
<i:Interaction.Triggers>
<i:EventTrigger EventName="PreviewMouseLeftButtonDown">
<cmd:EventToCommand Command="{Binding PreviewMouseLeftButtonDownCommand}" PassEventArgsToCommand="True"/>
</i:EventTrigger>
</i:Interaction.Triggers>
<TextBlock Text="Something" >
<i:Interaction.Triggers>
<i:EventTrigger EventName="KeyUp">
<cmd:EventToCommand Command="{Binding KeyUpCommand}" PassEventArgsToCommand="True"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</TextBlock>
<TextBlock Text="Something" />
<TextBlock Text="Something" />
<TextBlock Text="Something" />
<TextBlock Text="Something" />
</ListBox>
</Expander>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</Grid>
Can you tell me what is the problem and how can I fix it?
Add
GalaSoft.MvvmLight
library to references. Thenuse this
xmlns:cmd="clr-namespace:GalaSoft.MvvmLight;assembly=GalaSoft.MvvmLight"
instead ofxmlns:cmd="http://www.galasoft.ch/mvvmlight"
EventToCommand
is part of MVVM-Light ... Here's an article on MSDN by the writter of MVVM light (Laurent Bugnion), where he talks about how to use it.You can also look at a similar answer here, but I guess your options are either using MVVM-Light if you want to use it, or sorting through he's code and implementing something similar yourself ...
There is a good list of all behaviors and triggers that are available in Catel and how you can use them:
https://catelproject.atlassian.net/wiki/pages/viewpage.action?pageId=1409064
It also includes EventToCommand:
https://catelproject.atlassian.net/wiki/display/CTL/EventToCommand