WPF通过WCF将图像绑定到ViewModel中的TileLayoutControl

WPF通过WCF将图像绑定到ViewModel中的TileLayoutControl,wpf,image,wcf,xaml,binding,Wpf,Image,Wcf,Xaml,Binding,我的系统是这样工作的。我有一个WCF服务,它给我ImageUrl,我正在将这个图像下载到我的项目目录,并保存到我的文件系统。然后我想在Devexpress TileLayoutControl中动态显示此图像。但并没有在UI上显示任何内容。我也并没有得到错误。我试图给出像这样的图像源../MenuPhotos/imagename和像这样的/TileExample;组件/MenuPhotos/imagename 我的代码是这样的 IEnumerable<ImageItemsModel>

我的系统是这样工作的。我有一个WCF服务,它给我ImageUrl,我正在将这个图像下载到我的项目目录,并保存到我的文件系统。然后我想在Devexpress TileLayoutControl中动态显示此图像。但并没有在UI上显示任何内容。我也并没有得到错误。我试图给出像这样的图像源../MenuPhotos/imagename和像这样的/TileExample;组件/MenuPhotos/imagename

我的代码是这样的

IEnumerable<ImageItemsModel> items;
public GroupedItemsViewModel()
{
}
public IEnumerable<ImageItemsModel> Items
{
    get { return items; }
    private set { SetProperty<IEnumerable<ImageItemsModel>>(ref items, value, "Items"); }
}
public void LoadState(object navigationParameter)
{
    MyServiceclient = new MyServiceclient();
    var items = client.GetAllItems(null);
    string remoteUri = "http://example.com/";
    foreach (var item in items)
    {
        if (item.BackgroundImageUrl == null)
        {
            item.BackgroundImageUrl = "/TileExample;component/Assets/Images/user.jpg";
        }
        else
        {

            string remotefilepath = item.BackgroundImageUrl.Replace("../", "").Replace("//", "/");
            string remotefilename = remotefilepath.Replace("img/integration/Dashboard/bg/", "");
            string myStringWebResource = null;
            using (WebClient myWebClient = new WebClient())
            {
                string path = @"C:\Users\USER\Documents\Visual Studio 2013\Projects\TileExample\TileExample\MenuPhotos\";
                string checkpath = @"C:\Users\USER\Documents\Visual Studio 2013\Projects\TileExample\TileExample\MenuPhotos\" + remotefilename;
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }
                if (!File.Exists(checkpath))
                {
                    myStringWebResource = remoteUri + remotefilepath;
                    try
                    {
                        string downloadintopath = Path.Combine(path, remotefilename);
                        myWebClient.DownloadFile(myStringWebResource, downloadintopath);
                    }
                    catch { }
                }
            }

            item.BackgroundImageUrl = item.BackgroundImageUrl.Replace("../../img/integration/Dashboard/bg", "../MemberPhotos");
        }

    }

    Items = items;
}
#region INavigationAware Members
public void NavigatedFrom(NavigationEventArgs e)
{
}
public void NavigatedTo(NavigationEventArgs e)
{
    LoadState(e.Parameter);
}
public void NavigatingFrom(NavigatingEventArgs e)
{
}
#endregion
XAML

我的视图模型是这样的

IEnumerable<ImageItemsModel> items;
public GroupedItemsViewModel()
{
}
public IEnumerable<ImageItemsModel> Items
{
    get { return items; }
    private set { SetProperty<IEnumerable<ImageItemsModel>>(ref items, value, "Items"); }
}
public void LoadState(object navigationParameter)
{
    MyServiceclient = new MyServiceclient();
    var items = client.GetAllItems(null);
    string remoteUri = "http://example.com/";
    foreach (var item in items)
    {
        if (item.BackgroundImageUrl == null)
        {
            item.BackgroundImageUrl = "/TileExample;component/Assets/Images/user.jpg";
        }
        else
        {

            string remotefilepath = item.BackgroundImageUrl.Replace("../", "").Replace("//", "/");
            string remotefilename = remotefilepath.Replace("img/integration/Dashboard/bg/", "");
            string myStringWebResource = null;
            using (WebClient myWebClient = new WebClient())
            {
                string path = @"C:\Users\USER\Documents\Visual Studio 2013\Projects\TileExample\TileExample\MenuPhotos\";
                string checkpath = @"C:\Users\USER\Documents\Visual Studio 2013\Projects\TileExample\TileExample\MenuPhotos\" + remotefilename;
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }
                if (!File.Exists(checkpath))
                {
                    myStringWebResource = remoteUri + remotefilepath;
                    try
                    {
                        string downloadintopath = Path.Combine(path, remotefilename);
                        myWebClient.DownloadFile(myStringWebResource, downloadintopath);
                    }
                    catch { }
                }
            }

            item.BackgroundImageUrl = item.BackgroundImageUrl.Replace("../../img/integration/Dashboard/bg", "../MemberPhotos");
        }

    }

    Items = items;
}
#region INavigationAware Members
public void NavigatedFrom(NavigationEventArgs e)
{
}
public void NavigatedTo(NavigationEventArgs e)
{
    LoadState(e.Parameter);
}
public void NavigatingFrom(NavigatingEventArgs e)
{
}
#endregion

在UI中,我看不到关于我的图像的任何信息。如果我将图像作为源包含到visual studio中,它将正常工作。但我将作为服务填充到图像中。因此,我无法使用此解决方案。谢谢。

您好,最近我了解到此解决方案:

在.NET4.5中,动态映像路径应该是这样的

<Image Source="pack://application:,,,/TileExample;component/MenuPhotos/restaurant1.jpg"></Image>
这个解决方案对我有效