我对使用 MVVM Light 很陌生,所以希望这是一个简单的解决方法,尽管我花了大部分时间来寻找答案:-(
在我的xml中
<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>
在我的视图模型中
public RelayCommand<int> ViewDocumentTextCommand { get; private set; }
public FindModel()
{
.
.
.
ViewDocumentTextCommand = new RelayCommand<Int32>(p => { ViewDocumentText(p); });
}
public void ViewDocumentText(Int32 iDocumentID)
{
.
.
.
}
SearchResults.iUniqueID 是一个 Int32
出于某种原因,当按下按钮时,这会引发上述异常。
谢谢