DCSIMG
Quick WPF tip: Alternative text for images - Just code - Tamir Khason
Monday, July 30, 2007 12:02 PM Tamir Khason

Quick WPF tip: Alternative text for images

[This blog was migrated. You will not be able to comment here.
The new URL of this post is http://khason.net/blog/quick-wpf-tip-alternative-text-for-images/]


In HTML we have Alt tag, that provides alternative text for images (in case, that image is not exists), but what to do in XAML? Simple, use the power of DataTemplates and DataTriggers. In following example, I have data item with following properties Logo, which is Bitmap, Name and Description, that strings. I want to display Name text, in case, I have or want to disable no logo bitmap. Following code.

    
<DataTemplate x:Key="tmpProvider">
<
Grid>
<
TextBlock TextBlock.FontWeight="Bold" Text="{Binding Path=Name}" Visibility="Collapsed" Name="AltText"/>
<
Image Stretch="UniformToFill" Source="{Binding Path=Logo}" Name="Image" TextSearch.Text="{Binding Path=Name, Mode=OneWay}"/>
<
Grid.ToolTip>
<
StackPanel>
<
TextBlock Text="{Binding Path=Name}"/>
<
TextBlock Text="{Binding Path=Description}"/>
</
StackPanel>
</
Grid.ToolTip>
</
Grid>
<
DataTemplate.Triggers>
<
DataTrigger Binding="{Binding Path=Logo}" Value="{x:Null}">
<
Setter TargetName="AltText" Property="Visibility" Value="Visible"/>
</
DataTrigger>
</
DataTemplate.Triggers>
</
DataTemplate></PRE< P>

&#xA0;

Simple, isn't it? Thank all, those where 10 seconds about another accessibility pattern in WPF

תגים:, ,

Comments

No Comments