I finally found the answer to my problem. It was an issue of the datagrid, which in our case is embedded in a custom user control, being loaded more than once. The issue is explained here. Our custom user control is in a tab item of a tab control, which means it would fall victim to this problem. I used the solution on that Stack Overflow post to fix the issue.
Why does clicking on a datagrid cause the window to flash?
I'm working on a WPF app with a colleague at work. This app has a launch panel with 7 buttons. Clicking on any of the 7 buttons causes a new window to popup. These new windows all start with a datagrid, listing the contents of 1 of 7 tables, corresponding to the 7 buttons, etc.
The datagrid is actually a customized user control, that a third colleague wrote and which is being used in several other WPF applications. We have not modified it in this application. This customized user control is on the first tab of a tab control.
I'm responsible for one of those sub-windows that pops up when a user clicks on one of those buttons. The weird thing is that when a user clicks on one of the rows in the datagrid, the window flashes. And that's the thing that's really bugging me. I cannot figure out why it's flashing. And only this one window flashes, the other 6 don't. WHY??
Here's the XAML in my window, using the custom datagrid control:
<uc:CoreSummaryControl
x:Name="TheCoreSummaryControl"
Grid.Row="1"
CenterAlignedColumns="{StaticResource CenterAlignedFields}"
CenterAlignedHeaders="{StaticResource CenterAlignedHeaders}"
ExtraFields="{StaticResource ExtraFields}"
Fields="{Binding TableFields}"
LeftAlignedColumns="{StaticResource LeftAlignedFields}"
LeftAlignedHeaders="{StaticResource LeftAlignedHeaders}"
OmittedFields="{StaticResource OmittedFields}"
RightAlignedColumns="{StaticResource RightAlignedFields}"
RightAlignedHeaders="{StaticResource RightAlignedHeaders}"
ShowDateTimesHasDates="True" />
That XAML is identical to the other 6 windows' XAML.
Like I said, my colleague and I haven't changed the code of the CoreSummaryControl at all. I could, if you want, produce it here, but I don't see how it pertains, especially since the other 6 windows use the same control and even the same XAML to use that control. But it's that control that, when clicked on, causes my window to flash.
I believe that whatever the issue is, its related somehow to that CoreSummaryControl. But I will mention one other thing, which seems like it affects the flashing, but isn't related to CoreSummaryControl. The declaration of the tab control, on all 6 windows, includes this XAML:
<TabControl x:Name="ViewPort" Grid.Row="1"
Margin="0,0,0,0"
Background="Transparent"
BorderThickness="0"
SelectedIndex="{Binding ViewIndex, Mode=OneWay, UpdateSourceTrigger=PropertyChanged, IsAsync=True}"
SelectionChanged="ViewPort_SelectionChanged">
I want to draw your attention to the IsAsync=True attribute that's a part of the SelectedIndex. Out of curiosity, I removed that from my window. Once I did that, it appeared to have stopped the flashing. But WHY would it do that? And why only to my window?
2 additional answers
Sort by: Most helpful
-
kent vuong 1 Reputation point
2020-03-20T07:36:59.353+00:00 trust is to do what is said, not for the sake of your family and yourself to be responsible to the community
Honestly, you must know how to do your job well, regardless of people, to live to live -
Peter Fleischer (former MVP) 19,326 Reputation points
2020-03-20T09:51:13.38+00:00 Hi,
check your code. It's easy to reproduce your problem with following code:<Window x:Class="Window92" 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:WpfApp1" mc:Ignorable="d" Title="Flicking TabControl" Height="450" Width="800"> <StackPanel> <Label Content="{Binding ViewIndex}"/> <TabControl SelectedIndex="{Binding ViewIndex, UpdateSourceTrigger=PropertyChanged, IsAsync=True}" SelectionChanged="ViewPort_SelectionChanged"> <TabItem Header="TabItem 1"/> <TabItem Header="TabItem 2"/> <TabItem Header="TabItem 3"/> </TabControl> </StackPanel> </Window>
CodeBehind:
Imports System.ComponentModel Imports System.Runtime.CompilerServices Public Class Window92 Implements INotifyPropertyChanged Public Sub New() ' This call is required by the designer. InitializeComponent() ' Add any initialization after the InitializeComponent() call. Me.DataContext = Me End Sub Private Async Sub ViewPort_SelectionChanged(sender As Object, e As SelectionChangedEventArgs) Await Task.Delay(100) ViewIndex = 1 End Sub Private _viewIndex As Integer Public Property ViewIndex As Integer Get Return Me._viewIndex End Get Set(value As Integer) Me._viewIndex = value OnPropChanged() End Set End Property #Region " PropertyChanged" Public Event PropertyChanged As PropertyChangedEventHandler Implements INotifyPropertyChanged.PropertyChanged Friend Sub OnPropChanged(<CallerMemberName> Optional propName As String = "") RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(propName)) End Sub #End Region End Class