问题
I would like to have a method like ShowImageCommand = new RelayCommand<Image, Audio>(ShowImageMethod);
, but it's not possible, so I have created
public class AudioAndImage
{
public Image Picture { get; set; }
public Audio Sound { get; set; }
}
I have a new object of this type in ViewModel and set properties when Audiofile and Image are selected. But in the method which opens a new window
public void AnnotateImageMethod(AudioAndImage obj)
{
AnnotateImageWindow win = new AnnotateImageWindow(obj.Picture.Name, obj.Sound.AudioName);
}
I have thrown an exception System.InvalidCastException: 'Unable to cast object of type 'x.Model.Image' to type 'x.ViewModel.AudioAndImage'.', I double-checked all code and probably is about some converter or something about binding because I haven't change anything in XAML.
My logic is the following: I already have methods to handle opening audiofile and image selection. So I can create a new object and set his properties at those methods. Please, explain to me where I'm wrong?
Questions realated to the same app: ONE,TWO
来源:https://stackoverflow.com/questions/59172519/c-sharp-wpf-invalidcastexception-in-relaycommandt