我有一个如下定义的 DataTemplate
<DataTemplate x:Key="IconTextDataTemplate">
<StackPanel Orientation="Horizontal" Width="220" Height="60">
<Border Background="#66727272" Width="40" Height="40" Margin="10">
<Image Source="/SampleImage.png" Height="32" Width="32" Stretch="UniformToFill"/>
</Border>
<StackPanel Orientation="Vertical" VerticalAlignment="Center">
<TextBlock Text="{Binding Path=Title}" Margin="10,0,0,0" Width="170" Height="20" TextTrimming="WordEllipsis" />
<TextBlock Text="{Binding Path=NumberOfPhotos}" Margin="10,0,0,0" Width="170" Height="20" TextTrimming="WordEllipsis"/>
</StackPanel>
</StackPanel>
</DataTemplate>
然后我有一个使用 DataTemplate 的 GridView
<GridView x:Name="gv" Grid.Row="0" HorizontalAlignment="Left" Margin="0" VerticalAlignment="Top"
Width="Auto" Height="Auto" SelectionMode="Multiple" ItemTemplate="{StaticResource IconTextDataTemplate}" ItemsSource="{Binding}">
<GridView.ItemsPanel>
<ItemsPanelTemplate>
<WrapGrid MaximumRowsOrColumns="8"
VerticalChildrenAlignment="Top" HorizontalChildrenAlignment="Center" />
</ItemsPanelTemplate>
</GridView.ItemsPanel>
</GridView>
然后我将 GridViews dataContext 设置为一个集合
gv.DataContext = setCollection;
对象 setCollection 是具有 NumberOfPhotos 和 Title 属性的对象的集合,因此绑定
<TextBlock Text="{Binding Path=Title}" Margin="10,0,0,0" Width="170" Height="20" TextTrimming="WordEllipsis" />
<TextBlock Text="{Binding Path=NumberOfPhotos}" Margin="10,0,0,0" Width="170" Height="20" TextTrimming="WordEllipsis"/>
作品。但是,该对象没有 ImageSource 的属性
<Image Source="/SampleImage.png" Height="32" Width="32" Stretch="UniformToFill"/>
我不想绑定到对象的属性,而是想绑定到由两个字符串和对象的属性组成的复合结构,如下所示:
ImageSource = "/files/thumbnails/" + {Binding Path=Title} + fileType;
因此,在评估时,ImageSource 变为
/files/thumbnails/titleOfObject.png
其中 titleOfObject 等于此处的该值
<TextBlock Text="{Binding Path=Title}" Margin="10,0,0,0" Width="170" Height="20" TextTrimming="WordEllipsis" />
我怎样才能做到这一点?