Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 350029
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T11:30:48+00:00 2026-05-12T11:30:48+00:00

I have a data object — a custom class called Notification — that exposes

  • 0

I have a data object — a custom class called Notification — that exposes a IsCritical property. The idea being that if a notification will expire, it has a period of validity and the user’s attention should be drawn towards it.

Imagine a scenario with this test data:

_source = new[] {
    new Notification { Text = "Just thought you should know" },
    new Notification { Text = "Quick, run!", IsCritical = true },
  };

The second item should appear in the ItemsControl with a pulsing background. Here’s a simple data template excerpt that shows the means by which I was thinking of animating the background between grey and yellow.

<DataTemplate DataType="Notification">
  <Border CornerRadius="5" Background="#DDD">
    <Border.Triggers>
      <EventTrigger RoutedEvent="Border.Loaded">
        <BeginStoryboard>
          <Storyboard>
            <ColorAnimation 
              Storyboard.TargetProperty="Background.Color"
              From="#DDD" To="#FF0" Duration="0:0:0.7" 
              AutoReverse="True" RepeatBehavior="Forever" />
          </Storyboard>
        </BeginStoryboard>
      </EventTrigger>
    </Border.Triggers>
    <ContentPresenter Content="{TemplateBinding Content}" />
  </Border>
</DataTemplate>

What I’m unsure about is how to make this animation conditional upon the value of IsCritical. If the bound value is false, then the default background colour of #DDD should be maintained.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T11:30:48+00:00Added an answer on May 12, 2026 at 11:30 am

    The final part of this puzzle is… DataTriggers. All you have to do is add one DataTrigger to your DataTemplate, bind it to IsCritical property, and whenever it’s true, in it’s EnterAction/ExitAction you start and stop highlighting storyboard. Here is completely working solution with some hard-coded shortcuts (you can definitely do better):

    Xaml:

    <Window x:Class="WpfTest.Window1"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="Notification Sample" Height="300" Width="300">
      <Window.Resources>
        <DataTemplate x:Key="NotificationTemplate">
          <Border Name="brd" Background="Transparent">
            <TextBlock Text="{Binding Text}"/>
          </Border>
          <DataTemplate.Triggers>
            <DataTrigger Binding="{Binding IsCritical}" Value="True">
              <DataTrigger.EnterActions>
                <BeginStoryboard Name="highlight">
                  <Storyboard>
                    <ColorAnimation 
                      Storyboard.TargetProperty="(Panel.Background).(SolidColorBrush.Color)"
                      Storyboard.TargetName="brd"
                      From="#DDD" To="#FF0" Duration="0:0:0.5" 
                      AutoReverse="True" RepeatBehavior="Forever" />
                  </Storyboard>
                </BeginStoryboard>
              </DataTrigger.EnterActions>
              <DataTrigger.ExitActions>
                <StopStoryboard BeginStoryboardName="highlight"/>
              </DataTrigger.ExitActions>
            </DataTrigger>
          </DataTemplate.Triggers>
        </DataTemplate>
      </Window.Resources>
      <Grid>
        <Grid.RowDefinitions>
          <RowDefinition Height="*"/>
          <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>
        <ItemsControl ItemsSource="{Binding Notifications}"
                      ItemTemplate="{StaticResource NotificationTemplate}"/>
        <Button Grid.Row="1"
                Click="ToggleImportance_Click"
                Content="Toggle importance"/>
      </Grid>
    </Window>
    

    Code behind:

    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Windows;
    
    namespace WpfTest
    {
      public partial class Window1 : Window
      {
        public Window1()
        {
          InitializeComponent();
          DataContext = new NotificationViewModel();
        }
    
        private void ToggleImportance_Click(object sender, RoutedEventArgs e)
        {
          ((NotificationViewModel)DataContext).ToggleImportance();
        }
      }
    
      public class NotificationViewModel
      {
        public IList<Notification> Notifications
        {
          get;
          private set;
        }
    
        public NotificationViewModel()
        {
          Notifications = new List<Notification>
                            {
                              new Notification
                                {
                                  Text = "Just thought you should know"
                                },
                              new Notification
                                {
                                  Text = "Quick, run!",
                                  IsCritical = true
                                },
                            };
        }
    
        public void ToggleImportance()
        {
          if (Notifications[0].IsCritical)
          {
            Notifications[0].IsCritical = false;
            Notifications[1].IsCritical = true;
          }
          else
          {
            Notifications[0].IsCritical = true;
            Notifications[1].IsCritical = false;
          }
        }
      }
    
      public class Notification : INotifyPropertyChanged
      {
        private bool _isCritical;
    
        public string Text { get; set; }
    
        public bool IsCritical
        {
          get { return _isCritical; }
          set
          {
            _isCritical = value;
            InvokePropertyChanged("IsCritical");
          }
        }
    
        public event PropertyChangedEventHandler PropertyChanged;
    
        private void InvokePropertyChanged(string name)
        {
          var handler = PropertyChanged;
          if (handler != null)
          {
            handler(this, new PropertyChangedEventArgs(name));
          }
        }
      }
    }
    

    Hope this helps :).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 217k
  • Answers 217k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer the database itself should be ACID compliant, so i doubt… May 12, 2026 at 11:26 pm
  • Editorial Team
    Editorial Team added an answer You can easily get block of records using Take and… May 12, 2026 at 11:26 pm
  • Editorial Team
    Editorial Team added an answer I assume that you're talking about hiding the link to… May 12, 2026 at 11:26 pm

Related Questions

I have a data object with three fields, A, B and C. The problem
I have a data object (let's say it's called 'Entry') that has a set
I have a data object -- a custom class called Notification -- that exposes
I have a data object used to contain my UI data that supports INotifyPropertyChanged
I have a WPF ListBox bound to a data object. Inside the listbox are

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.