Click here to Skip to main content
15,438,113 members
Home / Discussions / WPF
   

WPF

 
AnswerRe: Is it possible to share SQL Server database between WPF application and Ionic application Pin
Mycroft Holmes28-Mar-22 12:28
professionalMycroft Holmes28-Mar-22 12:28 
QuestionDataTrigger not working Pin
Kevin Marois7-Mar-22 8:35
professionalKevin Marois7-Mar-22 8:35 
AnswerRe: DataTrigger not working Pin
Dave Kreskowiak7-Mar-22 10:27
mveDave Kreskowiak7-Mar-22 10:27 
AnswerRe: DataTrigger not working Pin
Richard Deeming7-Mar-22 21:15
mveRichard Deeming7-Mar-22 21:15 
GeneralRe: DataTrigger not working Pin
Kevin Marois8-Mar-22 5:32
professionalKevin Marois8-Mar-22 5:32 
QuestionQuestion about NotifyCollectionChangedEventArgs Pin
Super Lloyd1-Mar-22 12:12
MemberSuper Lloyd1-Mar-22 12:12 
AnswerRe: Question about NotifyCollectionChangedEventArgs Pin
Richard Deeming1-Mar-22 21:42
mveRichard Deeming1-Mar-22 21:42 
QuestionAnimation on DataGridRow jumps to wrong row when scrolling Pin
Mc_Topaz27-Feb-22 23:31
MemberMc_Topaz27-Feb-22 23:31 
I have a DataGrid where we display an animation on DataGridRows when a property in the ItemSource is set.

If the height of the DataGrid is enough low to display the VerticalScrollBar, I can scroll up and down and see the animations jump to the wrong rows.

I have made code snippet that reproduce the issue:
* The code shuld be "copy-paste".
* The DataGrid displays a list of Persons.
* If a person's HasBirthday = true the corresponding DataGridRow displays the animation.
* The first item in the list has HasBirthday = true.

To reproduce
1) Notice the first row has the animation running already.
2) Click the second row in the Grid.
3) Scroll down.
3) Some other row should now also have the animation on it.

Scrolling up and down a couple of times should also diplay the issue.

* Any explanation why this happens?
* Any suggestions how to fix this?


/BR
Steffe

XAML
<Window x:Class="Main.Views.DataGridCustomAnimation"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:Main.Views"
        mc:Ignorable="d"
        Loaded="Window_Loaded"
        Title="DataGridCustomAnimation" Height="450" Width="800">

    <Window.Resources>
        <Style TargetType="{x:Type DataGridRow}" x:Key="DataGridRowSmallStyle">
            <Setter Property="Foreground" Value="Blue" />
            <Setter Property="Background" Value="LightGray" />
            <Setter Property="MinHeight" Value="26" />
            <Style.Triggers>
                <Trigger Property="IsMouseOver" Value="True">
                    <Setter Property="Background" Value="Gray" />
                </Trigger>
            </Style.Triggers>
        </Style>
    </Window.Resources>

    <Grid Margin="20">
        <Grid.RowDefinitions>
            <RowDefinition Height="*" />
            <RowDefinition Height="20" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>

        <DataGrid x:Name="grid"
                  Grid.Row="0"
                  AutoGenerateColumns="True">
            <DataGrid.Resources>
                <Style BasedOn="{StaticResource DataGridRowSmallStyle}" TargetType="{x:Type DataGridRow}">
                    <Style.Triggers>
                        <MultiDataTrigger>
                            <MultiDataTrigger.Conditions>
                                <Condition Binding="{Binding HasBirthday}" Value="True" />
                                <Condition Binding="{Binding IsMouseOver, RelativeSource={RelativeSource Self}}" Value="False" />
                                <Condition Binding="{Binding IsSelected, RelativeSource={RelativeSource Self}}" Value="False" />
                            </MultiDataTrigger.Conditions>
                            <MultiDataTrigger.EnterActions>
                                <BeginStoryboard>
                                    <Storyboard RepeatBehavior="Forever">
                                        <ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(DataGridRow.Background).(SolidColorBrush.Color)">
                                            <EasingColorKeyFrame KeyTime="0:0:0.0" Value="#ca0516"/>
                                            <EasingColorKeyFrame KeyTime="0:0:1.0" Value="#ca0516"/>
                                            <EasingColorKeyFrame KeyTime="0:0:2.0" Value="#db552c"/>
                                            <EasingColorKeyFrame KeyTime="0:0:3.0" Value="#ca0516"/>
                                        </ColorAnimationUsingKeyFrames>

                                        <!-- Note: -->
                                        <!-- Cannot set the Foreground to white with a 'setter' when using an animation. -->
                                        <ColorAnimation Storyboard.TargetProperty="(DataGridRow.Foreground).(SolidColorBrush.Color)"
                                                        From="White"
                                                        To="White" />
                                    </Storyboard>
                                </BeginStoryboard>
                            </MultiDataTrigger.EnterActions>
                        </MultiDataTrigger>
                    </Style.Triggers>
                </Style>
            </DataGrid.Resources>
        </DataGrid>

        <Button Grid.Row="2" Height="40" Width="40" Content="Test" Click="Test_Clicked" />
    </Grid>
</Window>
C# code behind
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace Main.Views
{
    /// <summary>
    /// Interaction logic for DataGridCustomAnimation.xaml
    /// </summary>
    public partial class DataGridCustomAnimation : Window
    {
        public DataGridCustomAnimation()
        {
            InitializeComponent();
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            var list = new List<Person>();
            for (int i = 0; i < 40; i++)
            {
                list.Add(new Person
                {
                    Name = $"Person {i}"
                });
            }
            list.First().HasBirthday = true;
            grid.ItemsSource = list;
        }

        private void Test_Clicked(object sender, RoutedEventArgs e)
        {
            var hasBirthdays = (grid.ItemsSource as List<Person>).Where(x => x.HasBirthday);
            Console.WriteLine(hasBirthdays.Count());
        }
    }

    public class Person
    {
        public string Name { get; set; }
        public bool HasBirthday { get; set; }
        public bool IsDead { get; set; }
    }
}

AnswerRe: Animation on DataGridRow jumps to wrong row when scrolling Pin
Gerry Schmitz28-Feb-22 8:11
mveGerry Schmitz28-Feb-22 8:11 
GeneralRe: Animation on DataGridRow jumps to wrong row when scrolling Pin
Mc_Topaz28-Feb-22 20:28
MemberMc_Topaz28-Feb-22 20:28 
QuestionLabelprint on Thermotransfer Pin
Member 118002289-Feb-22 0:34
MemberMember 118002289-Feb-22 0:34 
QuestionRe: Labelprint on Thermotransfer Pin
Eddy Vluggen9-Feb-22 3:13
professionalEddy Vluggen9-Feb-22 3:13 
QuestionWPF c# onStartUp() view model problem with multiple data inputs Pin
StealthRT5-Feb-22 7:31
MemberStealthRT5-Feb-22 7:31 
AnswerRe: WPF c# onStartUp() view model problem with multiple data inputs Pin
Gerry Schmitz5-Feb-22 18:16
mveGerry Schmitz5-Feb-22 18:16 
AnswerRe: WPF c# onStartUp() view model problem with multiple data inputs Pin
Kevin Marois21-Feb-22 11:29
professionalKevin Marois21-Feb-22 11:29 
QuestionWpf System.Windows.Media.ImageSourcesConverter cannot be applied Pin
StealthRT1-Feb-22 16:08
MemberStealthRT1-Feb-22 16:08 
AnswerRe: Wpf System.Windows.Media.ImageSourcesConverter cannot be applied Pin
Richard Deeming1-Feb-22 21:49
mveRichard Deeming1-Feb-22 21:49 
GeneralRe: Wpf System.Windows.Media.ImageSourcesConverter cannot be applied Pin
StealthRT2-Feb-22 2:39
MemberStealthRT2-Feb-22 2:39 
GeneralRe: Wpf System.Windows.Media.ImageSourcesConverter cannot be applied Pin
Richard Deeming2-Feb-22 2:44
mveRichard Deeming2-Feb-22 2:44 
Question(beginner) There must be a better way (TextBlock properties) Pin
Maximilien26-Jan-22 5:08
MemberMaximilien26-Jan-22 5:08 
AnswerRe: (beginner) There must be a better way (TextBlock properties) Pin
Richard Deeming26-Jan-22 5:33
mveRichard Deeming26-Jan-22 5:33 
GeneralRe: (beginner) There must be a better way (TextBlock properties) Pin
Maximilien26-Jan-22 9:10
MemberMaximilien26-Jan-22 9:10 
QuestionConverting a byte[] to a ImageSource means huge memory leak Pin
Starwer24-Jan-22 11:42
MemberStarwer24-Jan-22 11:42 
AnswerRe: Converting a byte[] to a ImageSource means huge memory leak Pin
Gerry Schmitz24-Jan-22 16:15
mveGerry Schmitz24-Jan-22 16:15 
GeneralRe: Converting a byte[] to a ImageSource means huge memory leak Pin
Starwer24-Jan-22 19:58
MemberStarwer24-Jan-22 19:58 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.