我在列表框中显示图像。通过列表框的datacontext绑定使用对象的图像控件的源代码。WPF - Listbox内部的图像控件
问题:如果url没有图像,我想显示没有图像(图像)。是否有可能在xaml代码中做到这一点。
代码:
<ListBox ClipToBounds="False" x:Name="lbBestSellerImage" Width="Auto"
ItemsSource="{Binding}" ItemsPanel="{DynamicResource iptListBox}"
ItemContainerStyle="{DynamicResource ListBoxItemStyle}" />
<Style x:Key="ListBoxItemStyle" TargetType="{x:Type ListBoxItem}">
<Setter Property="Background" Value="Transparent"/>
<Setter Property="Padding" Value="2,0,0,0"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ListBoxItem}">
<Grid Width="150">
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<Image HorizontalAlignment="Center" VerticalAlignment="Center" Grid.Row="0" x:Name="img" Source="{Binding ImageUrl}" Height="74" Stretch="Fill" Width="75"/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
要显示*文字*'无图像吗?或者您只是想要没有图像吗? – slugster 2010-10-07 05:23:36
“无图像”是图像中的文字。如果项目没有图像,我想显示此图像。 – Geeth 2010-10-07 05:37:39