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>
Simple, isn't it? Thank all, those where 10 seconds about another accessibility pattern in WPF
No comments:
Post a Comment