给你一个集合,集合中每项都有两个字段用户头像地址(string)和在线状态(bool)
要求在Listbox中直接用绑定实现,大虾们帮帮忙呀
下面是我自己写的(但有问题):
<Image Width="50" x:Name="img" >
<Image.Resources>
<BitmapImage x:Key="OnLine" DecodePixelWidth="200" UriSource="{Binding HeadPic, Converter={StaticResource BitMapImgUriConvert}}"></BitmapImage>
<FormatConvertedBitmap x:Key="OffLine" Source="{StaticResource OnLine}" DestinationFormat="Gray32Float"/>
</Image.Resources>
<Image.Style>
<Style TargetType="Image">
<Style.Triggers>
<DataTrigger Binding="{Binding State}" Value="True">
<Setter Property="Source" Value="{StaticResource OnLine}"></Setter>
</DataTrigger>
<DataTrigger Binding="{Binding State}" Value="False">
<Setter Property="Source" Value="{StaticResource OffLine}"></Setter>
</DataTrigger>
</Style.Triggers>
</Style>
</Image.Style>
</Image>
可以的,你要保证Binding地方写正确