1
我在列表框中显示图像。如果图片网址没有图片,则会显示包含书名和作者姓名的文本块。WPF - 列表框中的控件
问题:如果图像可用,我想隐藏文本块。
代码:
<local:ImageConverter x:Key="myImageConverter"/>
<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" Grid.Row="0" VerticalAlignment="Center" x:Name="img" Source="{Binding ImageUrl}" Height="74" Stretch="Fill" Width="75"/>
-<TextBlock Name="txtblkImg" HorizontalAlignment="Center" VerticalAlignment="Center" Height="74" Width="75">
<TextBlock Text="{Binding Title}"/><LineBreak/>
<TextBlock Text="by "/>
<TextBlock Text="{Binding Author1}"/>
</TextBlock>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
谢谢你的响应。你能给一些示例代码吗? – Geeth 2010-10-13 10:45:51
如何传递图片url进行验证 – Geeth 2010-10-13 11:10:51
您想要做什么样的验证取决于您,例如,您可以检查该位置存在的文件,或者检查是否将其加载到位图中。 – 2010-10-13 11:42:33