|
I can't figure out how to attach a Caliburn.Micro Action to the MouseDoubleClick event.
This is a very common UI technique:
You have a list of items in a datagrid and you want to do something with the Item in the row when the user double-clicks the row.
I've found a few examples to get this to work using custom behaviors, but it seems silly to have to write that much code when the following works:
In view XAML:
<DataGrid Name="Surveys"
AutoGenerateColumns="False"
HeadersVisibility="Column"
IsReadOnly="True"
SelectionMode="Single">
<DataGrid.Columns>
<DataGridTextColumn Width="*"
Binding="{Binding Path=SurveyQuestion}"
Header="Survey Question" />
</DataGrid.Columns>
<DataGrid.RowStyle>
<Style TargetType="{x:Type DataGridRow}">
<EventSetter Event="MouseDoubleClick"
Handler="SurveyRowDoubleClick" />
</Style>
</DataGrid.RowStyle>
</DataGrid>
In code behind:
private void SurveyRowDoubleClick(object sender, RoutedEventArgs e)
{
IMyViewModel vm = (IMyViewModel)DataContext;
vm.ActivateCurrentSurvey();
}
In IMyViewModel interface:
public interface IMyViewModel
{
ICollection<Survey> Surveys { get; set; }
Survey CurrentSurvey { get; set; }
void AddSurvey();
void DeleteCurrentSurvey();
bool CanDeleteCurrentSurvey { get; }
void ActivateCurrentSurvey();
bool CanActivateCurrentSurvey { get; }
void RefreshSurveys();
}
Caliburn,.Micro automatically binds to the Surveys and CurrentSurvey properties (how cool!), but I can't find a way without using code behind or a custom Behavior to fire the EditCurrentSurvey method.
How about a datagrid binding convention that binds the double-click event to an ActivateCurrentXXX method?
|