|
<Window x:Class="PipedConverters.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:PipedConverters"
Title="PipedConverters" Height="300" Width="300"
FontSize="18"
>
<Window.Resources>
<!-- Loads the Tasks XML data. -->
<XmlDataProvider x:Key="xmlData" Source="..\..\data.xml" XPath="Tasks/Task" />
<!-- Converts the Status attribute text to the display name for that processing state. -->
<local:ValueConverterGroup x:Key="statusDisplayNameGroup">
<local:IntegerStringToProcessingStateConverter />
<local:EnumToDisplayNameConverter />
</local:ValueConverterGroup>
<!-- Converts the Status attribute text to a SolidColorBrush used to draw
the output of statusDisplayNameGroup. -->
<local:ValueConverterGroup x:Key="statusForegroundGroup">
<local:IntegerStringToProcessingStateConverter />
<local:ProcessingStateToColorConverter />
<local:ColorToSolidColorBrushConverter />
</local:ValueConverterGroup>
<!-- Converts the Status attribute to the tooltip message for that processing state. -->
<local:ValueConverterGroup x:Key="statusDescriptionGroup">
<local:XmlAttributeToStringStateConverter />
<local:IntegerStringToProcessingStateConverter />
<local:EnumToDescriptionConverter />
</local:ValueConverterGroup>
<DataTemplate x:Key="taskItemTemplate">
<StackPanel
Margin="2"
Orientation="Horizontal"
ToolTip="{Binding XPath=@Status, Converter={StaticResource statusDescriptionGroup}}"
>
<TextBlock Text="{Binding XPath=@Name}" />
<TextBlock Text=" (" xml:space="preserve" />
<TextBlock
Text="{Binding XPath=@Status, Converter={StaticResource statusDisplayNameGroup}}"
Foreground="{Binding XPath=@Status, Converter={StaticResource statusForegroundGroup}}" />
<TextBlock Text=")" />
</StackPanel>
</DataTemplate>
</Window.Resources>
<Grid >
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition />
</Grid.RowDefinitions>
<TextBlock
Background="Black"
Foreground="White"
HorizontalAlignment="Stretch"
Text="Tasks"
TextAlignment="Center" />
<ItemsControl
Grid.Row="1"
DataContext="{StaticResource xmlData}"
ItemsSource="{Binding}"
ItemTemplate="{StaticResource taskItemTemplate}" />
</Grid>
</Window>
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.