开发者

"specified cast is not valid" GalaSoft.MvvmLight.Command.RelayCommand`1.Execute(Object parameter)

I'm pretty new to using MVVM Light so hopefully this is a simple fix, although I have spent most of the day trying to track down an answer :-(

In my 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>

In my ViewModel

public RelayCommand<int> ViewDocumentTextCommand { get; private set; }
public FindModel() 
{
    .
    .
    .
    ViewDocumentTextCommand = new RelayCommand<Int32>(p => { ViewDocumentText(p); });
}

public void ViewDocumentText(Int32 iDocumentID)
{
    .
    .
    .
}

Search开发者_如何学运维Results.iUniqueID is an Int32

For some reason this is throwing the above exception when the button is pressed.

Thanks


Perhaps it's because your RelayCommand is defined as a RelayCommand<int> and you're trying to assign a RelayCommand<Int32> to it

Try changing your command definition to a simple ICommand instead.

It could also be that the value is null prior to the initial binding. Try using an object instead and not specifying the type.

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

and

public void ViewDocumentText(object iDocumentID)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜