Listing 3: XAML • Provide Visual Clues With Data Triggers

Setting the ItemsSource with no path or source arguments binds to the full collection that is the data context for the nearest ancestor with a non-null data context. Combining linear gradients and triggers displays an alert bar that extends from the right side of overdue items. Variations in the width of the red bar result from varying tab stops that repeat the transparent (white) color.

<UserControl x:Class="IncidentSelection"
	xmlns=
	"http://schemas.microsoft.com/winfx/2006/xaml/
	presentation"
	xmlns:biz="clr-namespace:TestApp"
	xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
	<UserControl.Resources>
	<SolidColorBrush 
		x:Key="AssignmentBorderBrush">Green</SolidColorBrush>
	<SolidColorBrush 
		x:Key="ResolvedBorderBrush">Blue</SolidColorBrush>
	<Color x:Key="Late">Red</Color>
	<Color x:Key="Due">Yellow</Color>
	<LinearGradientBrush x:Key="AssignmentLateBrush" 
		StartPoint="0, 0.5" EndPoint="1, .5">
	<GradientStop Offset="0" Color="Transparent"/>
	<GradientStop Offset=".6" Color='Transparent"/>
	<GradientStop Offset="1" Color="{StaticResource Late}"/>
	</LinearGradientBrush>

	<!— Linear Gradient Brushes for other states ommitted —>

	<DataTemplate x:Key="IncidentSelect">
	<Border  BorderThickness="1" BorderBrush="Gray" 
		Padding="6" Name="incidentBorder" Width="300" 
		HorizontalAlignment="Stretch">
	<StackPanel Name="incidentStackPanel" 
			HorizontalAlignment="Stretch">
	<TextBlock Text="{Binding Path=Title}" 
		FontWeight="Bold"/>
	</StackPanel>
	</Border>
	<DataTemplate.Triggers>
		<DataTrigger Binding="{Binding Path=IncidentState}">
		<DataTrigger.Value>AssignmentLate
			</DataTrigger.Value>
		<Setter Property="Background" 
			Value="{StaticResource AssignmentLateBrush}"  
			TargetName="incidentStackPanel"/>
		<Setter Property="BorderBrush" 
			Value="{StaticResource AssignmentBorderBrush}" 
			TargetName="incidentBorder" />
		<Setter Property="BorderThickness" Value="3"
			TargetName="incidentBorder" />
		<Setter Property="Padding" Value="1"
			TargetName="incidentBorder" />
	</DataTrigger>

	<!—Data triggers for other states ommitted —>

	</DataTemplate.Triggers>
	</DataTemplate>
	</UserControl.Resources>
	<StackPanel Orientation="Horizontal">
		<Label>Select Incident</Label>
		<ListBox Margin="5" ItemsSource="{Binding}"
			Background="White"
			IsSynchronizedWithCurrentItem="True"
			ItemTemplate="{StaticResource IncidentSelect}">
		</ListBox>
	</StackPanel>
</UserControl>
comments powered by Disqus

Featured

  • Mastering AI Development and Building AI Apps with GitHub Copilot

    Two Microsoft experts explain how GitHub Copilot is evolving from a coding assistant into a broader platform for building, customizing and testing AI-powered developer workflows.

  • VS Code 1.123 Adds Agent Session Sync, 1M Context Windows

    Microsoft released Visual Studio Code 1.123 on June 3, adding agent-focused features, larger model context support, integrated browser updates and a new delay for some automatic extension updates.

  • Copilot Billing Shock Hits Developers

    Developer complaints about GitHub Copilot's new usage-based billing model have centered on unexpectedly rapid AI credit consumption, and neither GitHub nor Microsoft has responded directly to the backlash, though they have previously published guidance to lessen model usage costs.

  • Hands On with GitHub Copilot App Technical Preview: Turning a Blazor Issue into a PR

    GitHub's brand-new Copilot desktop app, in technical preview, handled a small Blazor issue from planning through pull request creation, but the hands-on test also showed why developers still need to verify agent work in the running app before merging.

Subscribe on YouTube