2016-08-29 13 views
0

こんにちは皆私はxamarinアプリを開発しており、問題があります。 私は、XAMLに次のコードを持っている:イメージソースのバインディング値に文字列を追加するにはどうすればよいですか?

<ListView x:Name="listName"> 
    <ListView.ItemTemplate> 
    <DataTemplate> 
     <ViewCell> 
     <StackLayout Orientation="Vertical"> 
      <Image Source="{Binding imageName}"></Image> 
      <Label Text="{Binding name}" TextColor="Black"></Label> 
     </StackLayout> 
     </ViewCell> 
    </DataTemplate> 
    </ListView.ItemTemplate> 
</ListView> 

は、私は、文字列を追加するイメージソースプロパティを変更する必要があります。例:

<Image Source="{Binding imageName} + mystring.png"></Image> 
<Image Source="{Binding imageName + mystring.png}"></Image> 

xamlでこれを行うことはできますか? 可能だ?

答えて

1

これを行うにはコンバータを使用できます。

ページのアドオンのその後
public class ImagePostfixValueConverter 
    : IValueConverter 
{ 
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture) 
    { 
     var path = value as string; 
     var postfix = parameter as string; 

     if (string.IsNullOrEmpty(postfix) || string.IsNullOrEmpty(path)) 
      return value; 

     return path + postfix; 
    } 

    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) 
    { 
     throw new NotImplementedException(); 
    } 
} 

<ContentPage.Resources> 
    <ResourceDictionary> 
     <local:ImagePostfixValueConverter x:Key="PostfixConverter"/> 
    </ResourceDictionary> 
</ContentPage.Resources> 

そして、あなたの結合で:

<Image Source="{Binding imageName, Converter={StaticResouce PostfixConverter}, ConverterParameter=mystring.png}"></Image> 
関連する問題