Gorak Khule

Gorak Khule

  • NA
  • 27
  • 1.8k

WPF DataGrid with Expander perfomance issue on some machine.

Mar 15 2019 5:13 AM
Hi Team,
 
I am facing performance issue for DataGrid with expander on some machines and its working fine on some machines. I have used expander and group by in datagrid but for some machine working so is there any system dependencies.Actually performance issue with kyeboard type no any database connectivity and any c# events only keyboard and mouse click only in datagrid other page is working fine.Please help.
  1. <DataGrid Grid.Row="1" ColumnWidth="*" HorizontalAlignment="Left" AutoGenerateColumns="False" RowHeaderWidth="0" CanUserAddRows="False" x:Name="gdChannelElement" CanUserDeleteRows="False"  
  2. ItemsSource="{Binding Path=LstChannelElementModel}" CanUserSortColumns="True"  
  3. HorizontalScrollBarVisibility="Auto"  
  4. VerticalScrollBarVisibility="Auto"  
  5. CurrentItem="{Binding SelectedChannelElement}"  
  6. SelectedItem="{Binding SelectedChannelElement}" Grid.ColumnSpan="2"  
  7. IsReadOnly="{Binding Path= ChannelModel.IsReadOnly, UpdateSourceTrigger=PropertyChanged}">  
  8. <DataGrid.Columns>  
  9. <DataGridTemplateColumn Header="Title *" MinWidth="180" Width="Auto" SortMemberPath="Name">  
  10. <DataGridTemplateColumn.HeaderTemplate>  
  11. <DataTemplate>  
  12. <TextBlock Text="Name *" />  
  13. </DataTemplate>  
  14. </DataGridTemplateColumn.HeaderTemplate>  
  15. <DataGridTemplateColumn.CellTemplate>  
  16. <DataTemplate>  
  17. <TextBlock Text="{Binding Path=Name, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged,ValidatesOnDataErrors=True}" Style="{DynamicResource TblGridClass}" />  
  18. </DataTemplate>  
  19. </DataGridTemplateColumn.CellTemplate>  
  20. <DataGridTemplateColumn.CellEditingTemplate>  
  21. <DataTemplate>  
  22. <TextBox Text="{Binding Path=Name, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged,ValidatesOnDataErrors=True}" MaxLength="40" x:Name="test" FocusManager.FocusedElement="{Binding RelativeSource={RelativeSource Self}}" >  
  23. </TextBox>  
  24. </DataTemplate>  
  25. </DataGridTemplateColumn.CellEditingTemplate>  
  26. </DataGridTemplateColumn>  
  27. <DataGridTemplateColumn Header="Element Sub Type" MinWidth="170" Width="Auto" SortMemberPath="ElementSubType">  
  28. <DataGridTemplateColumn.HeaderTemplate>  
  29. <DataTemplate>  
  30. <StackPanel Style="{DynamicResource LOVStack}">  
  31. <TextBlock Text="Element Sub Type *" />  
  32. <Image Source="pack://application:,,,/Phoenix.CommonResources;component/Images/blueArrow.png" Style="{DynamicResource LOVImage}"></Image>  
  33. </StackPanel>  
  34. </DataTemplate>  
  35. </DataGridTemplateColumn.HeaderTemplate>  
  36. <DataGridTemplateColumn.CellTemplate>  
  37. <DataTemplate>  
  38. <TextBlock Text="{Binding Path=ElementSubType, ValidatesOnDataErrors=True}" Style="{DynamicResource TblGridClass}" />  
  39. </DataTemplate>  
  40. </DataGridTemplateColumn.CellTemplate>  
  41. <DataGridTemplateColumn.CellEditingTemplate>  
  42. <DataTemplate>  
  43. <TextBox Text="{Binding Path=ElementSubType, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged,ValidatesOnDataErrors=True}" x:Name="test" FocusManager.FocusedElement="{Binding RelativeSource={RelativeSource Self}}" >  
  44. <i:Interaction.Triggers>  
  45. <i:EventTrigger EventName="PreviewKeyDown">  
  46. <mvvmEvent:EventToCommand  
  47. Command="{Binding DataContext.ElementSubTypePreviewKeyDownCommand,Mode=OneWay,RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type DataGrid}}}"  
  48. PassEventArgsToCommand="True">  
  49. </mvvmEvent:EventToCommand>  
  50. </i:EventTrigger>  
  51. <i:EventTrigger EventName="LostFocus">  
  52. <mvvmEvent:EventToCommand  
  53. Command="{Binding DataContext.ElementSubTypeLostFocusCommand,Mode=OneWay,RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type DataGrid}}}"  
  54. PassEventArgsToCommand="True" >  
  55. </mvvmEvent:EventToCommand>  
  56. </i:EventTrigger>  
  57. </i:Interaction.Triggers>  
  58. </TextBox>  
  59. </DataTemplate>  
  60. </DataGridTemplateColumn.CellEditingTemplate>  
  61. <DataGridTemplateColumn.CellStyle>  
  62. <Style TargetType="{x:Type DataGridCell}">  
  63. <Style.Triggers>  
  64. <DataTrigger Binding="{Binding HasElementSubType}" Value="true">  
  65. <Setter Property="IsHitTestVisible" Value="True"/>  
  66. <Setter Property="IsTabStop" Value="True"/>  
  67. </DataTrigger>  
  68. <DataTrigger Binding="{Binding HasElementSubType}" Value="false">  
  69. <Setter Property="IsHitTestVisible" Value="False"/>  
  70. <Setter Property="IsTabStop" Value="False"/>  
  71. </DataTrigger>  
  72. </Style.Triggers>  
  73. </Style>  
  74. </DataGridTemplateColumn.CellStyle>  
  75. </DataGridTemplateColumn>  
  76. <!-- PHX-EN-803 Start -->  
  77. <DataGridTemplateColumn MinWidth="70" Header="Position" SortMemberPath="Position" IsReadOnly="{Binding IsPositionReadOnly}">  
  78. <DataGridTemplateColumn.CellTemplate>  
  79. <DataTemplate>  
  80. <TextBlock Text="{Binding Position,ValidatesOnDataErrors=True,ValidatesOnExceptions=True}" Style="{DynamicResource TblGridClass}"></TextBlock>  
  81. </DataTemplate>  
  82. </DataGridTemplateColumn.CellTemplate>  
  83. <DataGridTemplateColumn.CellEditingTemplate>  
  84. <DataTemplate>  
  85. <ComboBox Name="cmbPosition" MaxWidth="70" ItemsSource="{Binding PositionDropDownList}" HorizontalAlignment="Stretch" Margin="0"  
  86. DisplayMemberPath="Value1" SelectedValuePath="ID" SelectedValue="{Binding PositionId,UpdateSourceTrigger=PropertyChanged}" Text="{Binding Position,UpdateSourceTrigger=PropertyChanged,ValidatesOnDataErrors=True,ValidatesOnExceptions=True}" FocusManager.FocusedElement="{Binding RelativeSource={RelativeSource Self}}">  
  87. </ComboBox>  
  88. </DataTemplate>  
  89. </DataGridTemplateColumn.CellEditingTemplate>  
  90. <DataGridTemplateColumn.CellStyle>  
  91. <Style TargetType="{x:Type DataGridCell}">  
  92. <Style.Triggers>  
  93. <DataTrigger Binding="{Binding IsPositionReadOnly}" Value="true">  
  94. <Setter Property="IsEnabled" Value="False"/>  
  95. </DataTrigger>  
  96. </Style.Triggers>  
  97. </Style>  
  98. </DataGridTemplateColumn.CellStyle>  
  99. </DataGridTemplateColumn>  
  100. <DataGridTemplateColumn Header="Break" MinWidth="70" SortMemberPath="Break" IsReadOnly="{Binding Path= ChannelElementModel.IsReadOnlyBreak, UpdateSourceTrigger=PropertyChanged}">  
  101. <DataGridTemplateColumn.CellTemplate>  
  102. <DataTemplate>  
  103. <TextBlock Text="{Binding Path=Break,ValidatesOnDataErrors=True,ValidatesOnExceptions=True, UpdateSourceTrigger=PropertyChanged}" Style="{DynamicResource TblGridClass}" />  
  104. </DataTemplate>  
  105. </DataGridTemplateColumn.CellTemplate>  
  106. <DataGridTemplateColumn.CellEditingTemplate>  
  107. <DataTemplate>  
  108. <TextBox Width="50" IsReadOnly="{Binding Path= ChannelElementModel.IsReadOnlyBreak, UpdateSourceTrigger=PropertyChanged}" Text="{Binding Break,ValidatesOnDataErrors=True,ValidatesOnExceptions=True,UpdateSourceTrigger=PropertyChanged}" FocusManager.FocusedElement="{Binding RelativeSource={RelativeSource Self}}" MaxLength="20">  
  109. <i:Interaction.Triggers>  
  110. <i:EventTrigger EventName="PreviewKeyDown">  
  111. <mvvmEvent:EventToCommand Command="{Binding DataContext.ChannelBreakPreviewKeyDownCommand,RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type DataGrid}}}" PassEventArgsToCommand="True" />  
  112. </i:EventTrigger>  
  113. </i:Interaction.Triggers>  
  114. </TextBox>  
  115. </DataTemplate>  
  116. </DataGridTemplateColumn.CellEditingTemplate>  
  117. <DataGridTemplateColumn.CellStyle>  
  118. <Style TargetType="{x:Type DataGridCell}">  
  119. <Style.Triggers>  
  120. <DataTrigger Binding="{Binding IsReadOnlyBreak}" Value="true">  
  121. <Setter Property="IsEnabled" Value="False"/>  
  122. </DataTrigger>  
  123. </Style.Triggers>  
  124. </Style>  
  125. </DataGridTemplateColumn.CellStyle>  
  126. </DataGridTemplateColumn>  
  127. <!-- PHX-EN-803 End -->  
  128. <DataGridTemplateColumn Header="Media Id *" MinWidth="150" Width="Auto" SortMemberPath="MediaId">  
  129. <DataGridTemplateColumn.CellTemplate>  
  130. <DataTemplate>  
  131. <TextBlock Text="{Binding Path=MediaId, ValidatesOnDataErrors=True}" Style="{DynamicResource TblGridClass}" />  
  132. </DataTemplate>  
  133. </DataGridTemplateColumn.CellTemplate>  
  134. <DataGridTemplateColumn.CellEditingTemplate>  
  135. <DataTemplate>  
  136. <TextBox FocusManager.FocusedElement="{Binding RelativeSource={RelativeSource Self}}" MaxLength="32"  
  137. Text="{Binding MediaId, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged,ValidatesOnDataErrors=True}" >  
  138. <i:Interaction.Triggers>  
  139. <i:EventTrigger EventName="LostFocus">  
  140. <mvvmEvent:EventToCommand  
  141. Command="{Binding DataContext.MediaIdLostFocus,Mode=OneWay,RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type DataGrid}}}"  
  142. PassEventArgsToCommand="True"></mvvmEvent:EventToCommand>  
  143. </i:EventTrigger>  
  144. </i:Interaction.Triggers>  
  145. </TextBox>  
  146. </DataTemplate>  
  147. </DataGridTemplateColumn.CellEditingTemplate>  
  148. </DataGridTemplateColumn>  
  149. <!-- PHX-EN-803_Configuration of Channel Elements for Days Start -->  
  150. <mvvmEvent:DataGridDateColumn Header="Applicable Days" Width="auto" MinWidth="100">  
  151. <mvvmEvent:DataGridDateColumn.CellTemplate >  
  152. <DataTemplate>  
  153. <TextBlock Style="{DynamicResource TblGridClass}">  
  154. <Hyperlink IsEnabled ="{Binding IsApplicableDaysEnable}" Command="{Binding RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type DataGrid}}, Path=DataContext.ChannelGridDaysSelectCommand}">  
  155. View  
  156. </Hyperlink>  
  157. </TextBlock>  
  158. </DataTemplate>  
  159. </mvvmEvent:DataGridDateColumn.CellTemplate>  
  160. </mvvmEvent:DataGridDateColumn>  
  161. <!-- PHX-EN-803_Configuration of Channel Elements for Days End -->  
  162. <DataGridTemplateColumn Header="Duration *" MinWidth="110" Width="Auto" SortMemberPath="Duration">  
  163. <DataGridTemplateColumn.CellTemplate>  
  164. <DataTemplate>  
  165. <TextBlock Text="{Binding Path=Duration, ValidatesOnDataErrors=True}" Style="{DynamicResource TblGridClass}"/>  
  166. </DataTemplate>  
  167. </DataGridTemplateColumn.CellTemplate>  
  168. <DataGridTemplateColumn.CellEditingTemplate>  
  169. <DataTemplate>  
  170. <wpftoolkit:MaskedTextBox FocusManager.FocusedElement="{Binding RelativeSource={RelativeSource Self}}" Style="{DynamicResource DurationGridTextBoxClass}" Mask="00:00:00:00" Grid.Row="2" Grid.Column="5" Text="{Binding Duration, Mode=TwoWay, UpdateSourceTrigger=LostFocus,ValidatesOnDataErrors=True}" ></wpftoolkit:MaskedTextBox>  
  171. </DataTemplate>  
  172. </DataGridTemplateColumn.CellEditingTemplate>  
  173. </DataGridTemplateColumn>  
  174. <mvvmEvent:DataGridDateColumn Header="Start Date *" MinWidth="150" Width="Auto" SortMemberPath="StartDate">  
  175. <mvvmEvent:DataGridDateColumn.CellTemplate>  
  176. <DataTemplate>  
  177. <TextBlock Text="{Binding Path=StartDate,StringFormat= 'dd-MMM-yyyy', ValidatesOnDataErrors=True }" Style="{DynamicResource TblGridClass}" />  
  178. </DataTemplate>  
  179. </mvvmEvent:DataGridDateColumn.CellTemplate>  
  180. <mvvmEvent:DataGridDateColumn.CellEditingTemplate>  
  181. <DataTemplate>  
  182. <DatePicker FocusManager.FocusedElement="{Binding RelativeSource={RelativeSource Self}}" x:Name="dtStartDate" SelectedDate="{Binding Path=StartDate, StringFormat='dd-MMM-yyyy', Mode=TwoWay, UpdateSourceTrigger=PropertyChanged,ValidatesOnDataErrors=True}" >  
  183. <i:Interaction.Triggers>  
  184. <i:EventTrigger EventName="LostFocus">  
  185. <mvvmEvent:EventToCommand  
  186. Command="{Binding DataContext.StartDateLostFocusCommand,Mode=OneWay,RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type DataGrid}}}"  
  187. PassEventArgsToCommand="True" >  
  188. </mvvmEvent:EventToCommand>  
  189. </i:EventTrigger>  
  190. </i:Interaction.Triggers>  
  191. </DatePicker>  
  192. </DataTemplate>  
  193. </mvvmEvent:DataGridDateColumn.CellEditingTemplate>  
  194. </mvvmEvent:DataGridDateColumn>  
  195. <mvvmEvent:DataGridDateColumn Header="End Date *" MinWidth="150" Width="Auto" SortMemberPath="EndDate">  
  196. <mvvmEvent:DataGridDateColumn.CellTemplate>  
  197. <DataTemplate>  
  198. <TextBlock Text="{Binding Path=EndDate,StringFormat= 'dd-MMM-yyyy', ValidatesOnDataErrors=True }" Style="{DynamicResource TblGridClass}" />  
  199. </DataTemplate>  
  200. </mvvmEvent:DataGridDateColumn.CellTemplate>  
  201. <mvvmEvent:DataGridDateColumn.CellEditingTemplate>  
  202. <DataTemplate>  
  203. <DatePicker FocusManager.FocusedElement="{Binding RelativeSource={RelativeSource Self}}" SelectedDate="{Binding Path=EndDate, StringFormat='dd-MMM-yyyy', Mode=TwoWay, UpdateSourceTrigger=PropertyChanged,ValidatesOnDataErrors=True}" >  
  204. <i:Interaction.Triggers>  
  205. <i:EventTrigger EventName="LostFocus">  
  206. <mvvmEvent:EventToCommand  
  207. Command="{Binding DataContext.EndDateLostFocusCommand,Mode=OneWay,RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type DataGrid}}}"  
  208. PassEventArgsToCommand="True" >  
  209. </mvvmEvent:EventToCommand>  
  210. </i:EventTrigger>  
  211. </i:Interaction.Triggers>  
  212. </DatePicker>  
  213. </DataTemplate>  
  214. </mvvmEvent:DataGridDateColumn.CellEditingTemplate>  
  215. </mvvmEvent:DataGridDateColumn>  
  216. <DataGridTemplateColumn Header="Start Time" MinWidth="80" Width="Auto" SortMemberPath="StartTime">  
  217. <DataGridTemplateColumn.CellTemplate>  
  218. <DataTemplate>  
  219. <TextBlock Text="{Binding Path=StartTime,ValidatesOnDataErrors=True}" Style="{DynamicResource TblGridClass}" />  
  220. </DataTemplate>  
  221. </DataGridTemplateColumn.CellTemplate>  
  222. <DataGridTemplateColumn.CellEditingTemplate>  
  223. <DataTemplate>  
  224. <wpftoolkit:MaskedTextBox FocusManager.FocusedElement="{Binding RelativeSource={RelativeSource Self}}" Style="{DynamicResource TimeGridTextBoxClass}" Mask="00:00:00" Grid.Row="2" Grid.Column="5" Text="{Binding StartTime, Mode=TwoWay, UpdateSourceTrigger=LostFocus,ValidatesOnDataErrors=True}" ></wpftoolkit:MaskedTextBox>  
  225. </DataTemplate>  
  226. </DataGridTemplateColumn.CellEditingTemplate>  
  227. </DataGridTemplateColumn>  
  228. <DataGridTemplateColumn Header="End Time" MinWidth="80" Width="Auto" SortMemberPath="EndTime">  
  229. <DataGridTemplateColumn.CellTemplate>  
  230. <DataTemplate>  
  231. <TextBlock Text="{Binding Path=EndTime,ValidatesOnDataErrors=True}" Style="{DynamicResource TblGridClass}" />  
  232. </DataTemplate>  
  233. </DataGridTemplateColumn.CellTemplate>  
  234. <DataGridTemplateColumn.CellEditingTemplate>  
  235. <DataTemplate>  
  236. <wpftoolkit:MaskedTextBox FocusManager.FocusedElement="{Binding RelativeSource={RelativeSource Self}}" Style="{DynamicResource TimeGridTextBoxClass}" Mask="00:00:00" Grid.Row="2" Grid.Column="5" Text="{Binding EndTime, Mode=TwoWay, UpdateSourceTrigger=LostFocus,ValidatesOnDataErrors=True}" ></wpftoolkit:MaskedTextBox>  
  237. </DataTemplate>  
  238. </DataGridTemplateColumn.CellEditingTemplate>  
  239. </DataGridTemplateColumn>  
  240. <DataGridTemplateColumn Header="Active" MinWidth="50" Width="Auto" >  
  241. <DataGridTemplateColumn.CellTemplate>  
  242. <DataTemplate>  
  243. <CheckBox HorizontalAlignment="Center" IsChecked="{Binding Path=IsActive, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"  
  244. ></CheckBox>  
  245. </DataTemplate>  
  246. </DataGridTemplateColumn.CellTemplate>  
  247. <DataGridTemplateColumn.CellEditingTemplate >  
  248. <DataTemplate>  
  249. <CheckBox HorizontalAlignment="Center" FocusManager.FocusedElement="{Binding RelativeSource={RelativeSource Self}}"  
  250. IsChecked="{Binding Path=IsActive, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" ></CheckBox>  
  251. </DataTemplate>  
  252. </DataGridTemplateColumn.CellEditingTemplate>  
  253. </DataGridTemplateColumn>  
  254. <DataGridTextColumn Foreground="Black" MinWidth="80" Width="Auto" CellStyle="{StaticResource MyDataGridCell}" Header="Captured On" Binding="{Binding Path=CapturedOn,StringFormat='dd-MMM-yyyy'}" IsReadOnly="True" >  
  255. </DataGridTextColumn>  
  256. <DataGridTextColumn MinWidth="250" Width="*" Foreground="Black" Header="Comments" Binding="{Binding Path=Comment, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">  
  257. <DataGridTextColumn.EditingElementStyle>  
  258. <Style TargetType="TextBox">  
  259. <Setter Property="MaxLength" Value="120"/>  
  260. <Setter Property="CharacterCasing" Value="Upper"/>  
  261. </Style>  
  262. </DataGridTextColumn.EditingElementStyle>  
  263. </DataGridTextColumn>  
  264. </DataGrid.Columns>  
  265. <DataGrid.RowValidationErrorTemplate>  
  266. <ControlTemplate>  
  267. </ControlTemplate>  
  268. </DataGrid.RowValidationErrorTemplate>  
  269. <DataGrid.GroupStyle>  
  270. <!-- Style for groups at top level. -->  
  271. <GroupStyle>  
  272. <GroupStyle.HeaderTemplate>  
  273. <DataTemplate>  
  274. <StackPanel>  
  275. <TextBlock Text="{Binding Path=Name}" FontWeight="Bold" Padding="3"/>  
  276. </StackPanel>  
  277. </DataTemplate>  
  278. </GroupStyle.HeaderTemplate>  
  279. <GroupStyle.ContainerStyle>  
  280. <Style TargetType="{x:Type GroupItem}">  
  281. <Setter Property="Template">  
  282. <Setter.Value>  
  283. <ControlTemplate TargetType="{x:Type GroupItem}">  
  284. <Expander IsExpanded="{Binding IsExpanded1, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" x:Name="exptest" Height="Auto" HorizontalAlignment="Left"  
  285. VerticalAlignment="Stretch" >  
  286. <Expander.Header>  
  287. <StackPanel Orientation="Horizontal">  
  288. <TextBlock Text="{Binding Path=Name}" />  
  289. </StackPanel>  
  290. </Expander.Header>  
  291. <ItemsPresenter />  
  292. </Expander>  
  293. </ControlTemplate>  
  294. </Setter.Value>  
  295. </Setter>  
  296. </Style>  
  297. </GroupStyle.ContainerStyle>  
  298. </GroupStyle>  
  299. </DataGrid.GroupStyle>  
  300. <DataGrid.RowStyle>  
  301. <Style TargetType="{x:Type DataGridRow}">  
  302. <Style.Triggers>  
  303. <DataTrigger Binding="{Binding RecordStatus}" Value="Deleted">  
  304. <Setter Property="Visibility" Value="Collapsed"/>  
  305. </DataTrigger>  
  306. <DataTrigger Binding="{Binding IsVisible}" Value="False">  
  307. <Setter Property="Visibility" Value="Collapsed"/>  
  308. </DataTrigger>  
  309. </Style.Triggers>  
  310. </Style>  
  311. </DataGrid.RowStyle>  
  312. <i:Interaction.Triggers>  
  313. <i:EventTrigger EventName="PreviewKeyDown">  
  314. <mvvmEvent:EventToCommand  
  315. Command="{Binding ChannelElementPreviewKeyDownCommand,Mode=OneWay}"  
  316. PassEventArgsToCommand="True">  
  317. </mvvmEvent:EventToCommand>  
  318. </i:EventTrigger>  
  319. <i:EventTrigger EventName="GotKeyboardFocus">  
  320. <mvvmEvent:EventToCommand  
  321. Command="{Binding GridGotKeyboardFocus,Mode=OneWay}"  
  322. PassEventArgsToCommand="True">  
  323. </mvvmEvent:EventToCommand>  
  324. </i:EventTrigger>  
  325. </i:Interaction.Triggers>  
  326. <DataGrid.ContextMenu>  
  327. <ContextMenu>  
  328. <MenuItem Click="grdChannelElement_rightClick" Header="Export To Excel"/>  
  329. </ContextMenu>  
  330. </DataGrid.ContextMenu>  
  331. </DataGrid>  
  332. </Grid>  

Answers (1)