0

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>

しかし、アプリケーションを実行すると、完全に正常になります。

イメージ ソース バインディングのコンバーターを削除すると、無効な 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>

無効な XAML エラー

ソースコードのリンク: https://projects.developer.nokia.com/MeuPonto

4

2 に答える 2

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または空/デフォルトの画像を返す必要があります。

于 2013-03-04T21:17:08.753 に答える
-2

シンプルで、ソリューションを再構築するだけです。Build -> Rebuild sloution をクリックします。

于 2015-04-26T06:45:25.963 に答える