2014-12-05 71 views
0

我的系统是这样工作的。我有一个WCF服务,它给了我ImageUrl,我将这个图像下载到我的项目目录并保存到我的文件系统。然后,我想动态地在Devexpress TileLayoutControl中显示此图像。但是在UI上没有显示任何东西,我也没有收到错误。我试图给像这样../MenuPhotos/imagename像这样/ TileExample;组件/ MenuPhotos/imagenameWPF将图像通过WCF绑定到ViewModel的TileLayoutControl

我的代码是这样的;

XAML;

<dxlc:TileLayoutControl Name="TileList" AllowItemMoving="True" ItemsSource="{Binding Items}" ShowLayerSeparators="True" Padding="40,60,40,10" AllowLayerSizing="True" > 

    <dxlc:TileLayoutControl.Resources> 
     <Style TargetType="dxlc:Tile"> 
      <Setter Property="BorderBrush" Value="Blue" /> 
      <!--<Setter Property="Background" Value="{Binding BackgroundColor}" />--> 
      <Setter Property="Background" Value="{Binding BackgroundColor}" /> 
      <Setter Property="Size" Value="{Binding SizeType}" /> 
      <Setter Property="ContentTemplate"> 
       <Setter.Value> 
        <DataTemplate> 
         <Grid> 
         <Image Stretch="UniformToFill" HorizontalAlignment="Center" VerticalAlignment="Center"> 
           <Image.Source> 
            <BitmapImage UriSource="/TileExample;component/MenuPhotos/restaurant1.jpg" /> 
           </Image.Source> 
          </Image> 
          <Image Stretch="Uniform" Source="{Binding IconImageUrl}" HorizontalAlignment="Center" VerticalAlignment="Center" /> 
         </Grid> 
        </DataTemplate> 
       </Setter.Value> 
      </Setter> 
      <Setter Property="Header" Value="{Binding}" /> 
      <Setter Property="HeaderTemplate"> 
       <Setter.Value> 
        <DataTemplate> 
         <TextBlock Text="{Binding BackgroundImageUrl}" FontFamily="Segoe UI Light" FontSize="12" /> 
        </DataTemplate> 
       </Setter.Value> 
      </Setter> 
      <Setter Property="dxlc:TileLayoutControl.IsFlowBreak" Value="{Binding IsFlowBreak}" /> 
      <Setter Property="dxlc:TileLayoutControl.GroupHeader" Value="Menü" /> 
      <Setter Property="dxwuin:Navigation.NavigateTo" Value="{Binding PageName}" /> 
      <Setter Property="dxwuin:Navigation.NavigationParameter" Value="1" /> 
     </Style> 

     <Style TargetType="dxlc:TileGroupHeader"> 
      <Setter Property="Foreground" Value="#FFFFFFFF" /> 
     </Style> 

    </dxlc:TileLayoutControl.Resources> 
</dxlc:TileLayoutControl> 

而我的viewmodel是这样的;

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我想不出我的images.If什么也没有看到,我将包括图像作为一个源到Visual Studio其working.But我将填补图像作为一项服务。所以我不能使用这个解决方法。谢谢。

回答

0

嗨最近我学到了这个解决方案:

在.NET 4.5中动态图像路径应该是这样的。

<Image Source="pack://application:,,,/TileExample;component/MenuPhotos/restaurant1.jpg"></Image> 

此解决方案适用于我。

相关问题