ComboBoxのSelectedItemChangeEventをビューモデルのICommandに接続しました。すべてが正常に機能しているようですが、ComboxBoxのSelectedItemを取得する方法がわかりません。EventToCommandのCommandParameterを使用する必要があると思います-これを、ComboBoxのselectedItemを持つViewModel内の何かにバインドしますか?私はこれを試しました:
<ComboBox
Width="422"
Height="24"
DisplayMemberPath="Name"
ItemsSource="{Binding CategoryTypes}"
SelectedItem="{Binding SelectedCategory}"
>
<i:Interaction.Triggers>
<i:EventTrigger EventName="SelectionChanged">
<MvvmLight:EventToCommand
Command="{Binding SelectCategoryCommand,Mode=TwoWay}"
CommandParameter="{Binding SelectedCategory, Mode=TwoWay}"
MustToggleIsEnabledValue="True" />
</i:EventTrigger>
</i:Interaction.Triggers>
</ComboBox>
そして私のビューモデルでは:
public ICommand SelectCategoryCommand
{
get
{
return new SelectCategoryCommand(this);
}
}
public CategoryType SelectedCategory
{
get; set;
}
およびICommand
public class SelectCategoryCommand : ICommand
{
private RowViewModel _rowViewModel;
public SelectCategoryCommand(RowViewModel rowViewModel)
{
_rowViewModel = rowViewModel;
}
public bool CanExecute(object parameter)
{
return true;
}
public event EventHandler CanExecuteChanged;
public void Execute(object parameter)
{
CategoryType categoryType = (CategoryType) parameter;
}
}
ただし、ICommandのExecuteメソッドのパラメーターは常にnullです。私はSilverLightにかなり慣れていないので、ここで明らかな何かが本当に欠けていると思います。誰か助けてもらえますか?前もって感謝します!