0

我对使用 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

出于某种原因,当按下按钮时,这会引发上述异常。

谢谢

4

1 回答 1

2

也许是因为您的 RelayCommand 被定义为 aRelayCommand<int>并且您试图将 a 分配RelayCommand<Int32>给它

尝试将您的命令定义更改为简单的ICommand

也可能是在初始绑定之前该值为 null。尝试使用对象而不是指定类型。

new RelayCommand(p => ViewDocumentText(p));

public void ViewDocumentText(object iDocumentID)

于 2011-06-23T19:41:49.090 回答