我使用提供的xmal代码和c#代码得到以下异常。请帮忙。
异常:无法转换类型' MS.Internal.NamedObject'输入' System.IConvertible'
XAML代码:
<Grid x:Name="cheque1" Width="500" HorizontalAlignment="Left" Margin="{DynamicResource Cheque1Position}" Height="200" VerticalAlignment="Top" d:LayoutOverrides="Height">
<Grid.Visibility>
<MultiBinding Converter="{StaticResource ChequeVisibilityConverter}" ConverterParameter="0" diag:PresentationTraceSources.TraceLevel="None">
<Binding Path="_ItemDASFlowExtensions.DepositSummary.ScannedCheques"/>
<Binding Path="_Common.DynamicIndex" />
</MultiBinding>
</Grid.Visibility>
<Image x:Name="ChequeToBeReturned1" HorizontalAlignment="Right" Height="60" VerticalAlignment="Top" Width="76" Style="{DynamicResource ReturnCheque}" Margin="0,5,5,0">
<Image.Visibility>
<MultiBinding Converter="{StaticResource ChequeVisibilityConverter}" ConverterParameter="0, Validity" diag:PresentationTraceSources.TraceLevel="High">
<Binding Path="_ItemDASFlowExtensions.DepositSummary.ScannedCheques"/>
<Binding Path="_Common.DynamicIndex" />
</MultiBinding>
</Image.Visibility>
</Image>
</Grid>
public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
Visibility visibility = Visibility.Hidden;
IList<IChequeMediaItem> array = values[0] as IList<IChequeMediaItem>;
int dynIndex =-1 ;
if (values[1]!=null)
{
dynIndex = System.Convert.ToInt32(values[1]);
}
}
我在语句
处获得InvalidCastExceptiondynIndex = System.Convert.ToInt32(values[1]);
答案 0 :(得分:1)
_Common.DynamicIndex
未正确设置或绑定错误。在转换器中,它返回DependencyProperty.UnsetValue,相当于null。
转换器类很好,检查绑定是否正确完成并检查运行时该值是否为空。