我很新使用MVVM Light,所以希望這是一個簡單的修復,雖然我已經花了大部分時間試圖追查:-(「指定的投射無效」GalaSoft.MvvmLight.Command.RelayCommand`1.Execute(對象參數)
的答案在我的XAML
<sdk:DataGrid Name="m_dgResults" AutoGenerateColumns="False" IsReadOnly="True" AreRowDetailsFrozen="True" SelectionMode="Single" ItemsSource="{Binding SearchResults}" >
.
.
.
<Button x:Name="cmdFTSViewText" Width="24" Height="24" Margin="5" ToolTipService.ToolTip="View Text">
<Image Source="../Images/ViewDocumentText.png" Stretch="None"/>
<i:Interaction.Triggers>
<i:EventTrigger EventName="Click">
<cmd:EventToCommand Command="{Binding Source={StaticResource Locator}, Path=FindModel.ViewDocumentTextCommand}"
CommandParameter="{Binding iUniqueID}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</Button>
在我的ViewModel
public RelayCommand<int> ViewDocumentTextCommand { get; private set; }
public FindModel()
{
.
.
.
ViewDocumentTextCommand = new RelayCommand<Int32>(p => { ViewDocumentText(p); });
}
public void ViewDocumentText(Int32 iDocumentID)
{
.
.
.
}
SearchResults.iUniqueID是一個Int32
出於某種原因,當按下按鈕時,會引發上述異常。
感謝
可能重複http://stackoverflow.com/questions/2306063/canexecute-on-relaycommandt-not-工作) – Jehof