在设计器中没有出现绑定 Image.Source 到 属性

Binding Image.Source to property doesn't appear, in designer

我想将图像源(在 WinRT XAML 中)绑定到名为 ServiceEnvoy 的视图模型的图像源 属性,它指向我项目的 /Assets 目录中的图像。这是视图模型:

public class ServiceEnvoy
{
    public ServiceEnvoy(string name, ImageSource source)
    {
        this.Name = name;
        this.ImageSource = source;
    }

    public string Name { get; private set; }
    public ImageSource ImageSource { get; private set; }
}

这里是我要暴露视图模型的ListView的XAML:

<ListView ItemsSource="{Binding Services}" 
          ...>
    <ListView.ItemTemplate>
        <DataTemplate>
            <Button>
                <Button.Content>
                    <StackPanel Orientation="Horizontal">
                        <TextBlock Text="{Binding Name}"/> <!--Works fine-->
                        <Image Source="{Binding ImageSource}"/> <!--Does not-->
                    </StackPanel>
                </Button.Content>
            </Button>
        </DataTemplate>
    </ListView.ItemTemplate>
</ListView>

然而,还有另一个复杂的问题:视图模型从 JSON 反序列化以加载到主页上。

这是我目前的 JSON:

{
    "Services": [
        {
            "Name": "OneDrive",
            "Image": "onedrive.png"
        }
    ]
}

ServiceEnvoyExtractor class(在 Pastebin 上找到 here)通过将 "ms-appx:///Assets/" 附加到 "Image" 并从中创建一个 Uri/BitmapImage 来提取视图模型.我不确定这是否是问题所在,但我尝试将 JSON 更改为 "Image": "/Assets/onedrive.png""ms-appx:///Assets/onedrive.png" 并重建,但设计器仍然没有显示图像。但是,当我 运行 它在我的 phone.

上时它工作正常

我的d:DataContext是:d:DataContext="{Binding Source={d:DesignData Source=/Data/ServiceRecords.json, Type=data:DesignableServiceEnvoyCollection}}"

嗯,这很简单。

在对 ImageSource 的类型感到沮丧并重命名它并使用它测试其他控件并摆弄 JSON 几个小时后,我意识到虽然它的键是 "Image", 我绑定到 "ImageSource".

那个,并将其目录更改为 "Assets/onedrive.png" 解决了问题。

编辑: XAML 似乎也抛出了一个关于如何无法序列化 ImageSource 属性的错误;将 属性 更改为类型 string 解决了问题。