2013-03-14 25 views
0

結合文字和靜態文本是否有可能串聯結合文本與源圖像 一個靜態文本例如:串聯在源圖像

<Image Name="ImagePlace" Source="http://site.com/image/architecture.png" Grid.Column="0" /> 
<Image Name="ImagePlace" Source="{Binding Path=Ico}" Grid.Column="0" /> 

,我想以連接兩個來源。

我有一個名爲Category的對象列表,其中包含一個字段Icon,其中包含例如「architecture.png」。我將它綁定在一個列表中。 網站的網址不會更改,但圖像始終會更改。

<ListBox x:Name="ListboxCategories"> 
       <ListBox.ItemTemplate> 
        <DataTemplate> 
        <Button Name="category" Tag="{Binding Path=Id}" Tap="category_Tap_1"> 
         <Grid> 
          <Grid.ColumnDefinitions> 
           <ColumnDefinition Width="*"/> 
           <ColumnDefinition Width="2*"/> 
           <ColumnDefinition Width="*"/> 
          </Grid.ColumnDefinitions> 
          <Image Name="ImagePlace" Source="http://www.test.com/assets/images/icons/tags/architecture.png" Grid.Column="0" /> 
          <TextBlock Text="{Binding Path=Title}" Grid.Column="1" HorizontalAlignment="Center" /> 
          <Image Name="chevron" Grid.Column="2" Source="/Assets/AppBar/White/appbar.chevron.right.png" HorizontalAlignment="Right" Width="50" Height="50" /> 
         </Grid> 
        </Button> 
        </DataTemplate> 
       </ListBox.ItemTemplate> 
      </ListBox> 

回答

2

最乾淨的方式(當然,這取決於你的架構)將在你的對象添加屬性做串聯:

public string FullUri 
{ 
    get 
    { 
     return "http://site.com/image/" + this.Ico 
    } 
} 

另一種方法是使用自定義轉換器做級聯。

public object Convert(object value, Type targetType, object parameter, CultureInfo culture) 
{ 
    if (value == null) 
    { 
     return null; 
    } 

    return "http://site.com/image/" + value.ToString(); 
} 
+0

重飛思路! :)謝謝它的作品! – Volkan 2013-03-14 13:32:47