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