WPF - 具有 MultiBinding 的图像源

WPF - Image source with MultiBinding

在 WPF 中,如何通过 Multi 使用图像源:

<Image x:Name="imgLane1" HorizontalAlignment="Left"  Height="25" Margin="180,225,0,0" VerticalAlignment="Top" Width="42" Stretch="Fill">
                                        <Image.Source>
                                            <MultiBinding Converter="StaticResource LaneImageConverter}" UpdateSourceTrigger="PropertyChanged">
                                                <Binding Path="Attachments">
                                                <Binding Path="Delivery"/>
                                            </MultiBinding>
                                        </Image.Source>
                                    </Image>`
 public class LaneImageConverter : IMultiValueConverter
{
    public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
    {
        string path = "";
        int attachments = 0;
        string delivery = values[1].ToString();
        Int32.TryParse(values[0].ToString(), out attachments);
        return System.Windows.Data.Binding.DoNothing;
    }
    public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
    {
        throw new NotImplementedException();
    }
}

我无法使用 MultiBinding 更新 imageSource 也调试更新源 请帮帮我?

转换器必须 return 派生自 ImageSource 的 class 实例,例如从图像文件路径加载的BitmapImage

public object Convert(
    object[] values, Type targetType, object parameter, CultureInfo culture)
{
    string path = "";
    // compose path from values

    return new BitmapImage(new Uri(path));
}

当图像文件是程序集资源时,您将使用 Resource File Pack URI:

var uri = string.Format("pack://application:,,,/images/{0}{1}.png", values); // for example

return new BitmapImage(new Uri(uri));