我的ListBox有这个XAML:
<ListBox x:Name="LbBatidas" ItemsSource="{Binding Batidas}" Height="Auto" Grid.Row="3" Grid.ColumnSpan="2">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" Height="72">
<Image Source="{Binding Natureza, Converter={StaticResource NaturezaBatidaConverter}}" Width="72"/>
<TextBlock Text="{Binding Horario, StringFormat=\{0:HH:mm:ss\}}" VerticalAlignment="Center" FontSize="48" Margin="10,0,0,0"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
但是,当我运行我的应用程序时,它完全正常。
如果我删除了Image source的转换器绑定了无效XAML停止的错误
<ListBox x:Name="LbBatidas" ItemsSource="{Binding Batidas}" Height="Auto" Grid.Row="3" Grid.ColumnSpan="2">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" Height="72">
<Image Source="{Binding Natureza}" Width="72"/>
<TextBlock Text="{Binding Horario, StringFormat=\{0:HH:mm:ss\}}" VerticalAlignment="Center" FontSize="48" Margin="10,0,0,0"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
答案 0 :(得分:0)
尝试更改Convert和ConvertBack方法,如下所示:
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
var v = value as NaturezaBatida;
if (v == null)
return null;
var imageSource = v == NaturezaBatida.Entrada
? new Uri("/Imagens/Entrada.png", UriKind.RelativeOrAbsolute)
: new Uri("/Imagens/Saida.png", UriKind.RelativeOrAbsolute);
return new BitmapImage(imageSource);
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return value;
}
您应该在Convert方法中返回null或空/默认图像,而不是传入的对象。
答案 1 :(得分:-2)
简单只需重建您的解决方案。 点击Build - &gt;重建sloution