我在列表框中顯示圖像。通過列表框的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