From c2a3fde29b4e8dd0db9a73bef10c9b16e891e91d Mon Sep 17 00:00:00 2001
From: "harald.martini@student.tugraz.at" <harald.martini@student.tugraz.at>
Date: Mon, 21 Jun 2021 10:30:57 +0200
Subject: [PATCH] Added Autoscrollbehavior to OutputView

---
 .../Behaviours/AutoScrollDataGridBehaviour.cs | 64 +++++++++++++++++++
 VECTO3GUI2020/DataGridStyles.xaml             |  6 +-
 VECTO3GUI2020/VECTO3GUI2020.csproj            |  4 ++
 VECTO3GUI2020/Views/OutputView.xaml           | 24 ++++---
 VECTO3GUI2020/Views/OutputView.xaml.cs        |  3 +-
 VECTO3GUI2020/packages.config                 |  1 +
 .../output/exempted_primary_heavyBus.vsum     |  3 +
 7 files changed, 93 insertions(+), 12 deletions(-)
 create mode 100644 VECTO3GUI2020/Behaviours/AutoScrollDataGridBehaviour.cs
 create mode 100644 Vecto3GUI2020Test/TestData/output/exempted_primary_heavyBus.vsum

diff --git a/VECTO3GUI2020/Behaviours/AutoScrollDataGridBehaviour.cs b/VECTO3GUI2020/Behaviours/AutoScrollDataGridBehaviour.cs
new file mode 100644
index 0000000000..a8669cb427
--- /dev/null
+++ b/VECTO3GUI2020/Behaviours/AutoScrollDataGridBehaviour.cs
@@ -0,0 +1,64 @@
+using System;
+using System.Collections.Generic;
+using System.Collections.Specialized;
+using System.ComponentModel;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Controls;
+using Microsoft.Xaml.Behaviors;
+
+namespace VECTO3GUI2020.Behaviours
+{
+    public class AutoScrollDataGridBehaviour : Behavior<DataGrid>
+    {
+		#region Overrides of Behavior
+
+		private INotifyCollectionChanged sourceCollection;
+		protected override void OnAttached()
+		{
+			base.OnAttached();
+
+			//subsrice to Itemssource
+			var dpd = DependencyPropertyDescriptor.FromProperty(ItemsControl.ItemsSourceProperty, typeof(DataGrid));
+			if (dpd != null)
+			{
+				dpd.AddValueChanged(this.AssociatedObject, OnItemsSourceChanged);
+			}
+
+
+		}
+
+		private void OnItemsSourceChanged(object sender, EventArgs e)
+		{
+			UnSubscribeFromSourceCollectionChanged();
+
+			sourceCollection = AssociatedObject.ItemsSource as INotifyCollectionChanged;
+			if (sourceCollection != null) {
+				sourceCollection.CollectionChanged += SourceCollectionChanged;
+			}
+		}
+
+		private void SourceCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
+		{
+			var newIndex = e.NewStartingIndex;
+			this.AssociatedObject.ScrollIntoView(this.AssociatedObject.Items[newIndex]);
+		}
+
+
+		protected override void OnDetaching()
+		{
+			base.OnDetaching();
+			UnSubscribeFromSourceCollectionChanged();
+		}
+
+		private void UnSubscribeFromSourceCollectionChanged()
+		{
+			if (sourceCollection != null) {
+				sourceCollection.CollectionChanged -= SourceCollectionChanged;
+			}
+		}
+
+		#endregion
+	}
+}
diff --git a/VECTO3GUI2020/DataGridStyles.xaml b/VECTO3GUI2020/DataGridStyles.xaml
index 71273451d2..8eca24461f 100644
--- a/VECTO3GUI2020/DataGridStyles.xaml
+++ b/VECTO3GUI2020/DataGridStyles.xaml
@@ -37,7 +37,7 @@
     <Style x:Key="DataGridCellStyle1" TargetType="{x:Type DataGridCell}">
         <Setter Property="Background" Value="Transparent"/>
         <Setter Property="BorderBrush" Value="Transparent"/>
-        <Setter Property="BorderThickness" Value="1"/>
+        <Setter Property="BorderThickness" Value="0"/>
         <Setter Property="Template">
             <Setter.Value>
                 <ControlTemplate TargetType="{x:Type DataGridCell}">
@@ -53,7 +53,7 @@
                 <!-- <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.HighlightTextBrushKey}}"/>
                 <Setter Property="BorderBrush" Value="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}"/> -->
                 <Setter Property="Foreground" Value="Black"/>
-                <Setter Property="BorderBrush" Value="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}"/>
+                <!--<Setter Property="BorderBrush" Value="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}"/>-->
             </Trigger>
             <Trigger Property="IsKeyboardFocusWithin" Value="True">
                 <Setter Property="BorderBrush" Value="{DynamicResource {x:Static DataGrid.FocusBorderBrushKey}}"/>
@@ -64,7 +64,7 @@
                     <Condition Property="Selector.IsSelectionActive" Value="false"/>
                 </MultiTrigger.Conditions>
                 <Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.InactiveSelectionHighlightBrushKey}}"/>
-                <Setter Property="BorderBrush" Value="{DynamicResource {x:Static SystemColors.InactiveSelectionHighlightBrushKey}}"/>
+                <!--<Setter Property="BorderBrush" Value="{DynamicResource {x:Static SystemColors.InactiveSelectionHighlightBrushKey}}"/>-->
                 <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.InactiveSelectionHighlightTextBrushKey}}"/>
             </MultiTrigger>
             <Trigger Property="IsEnabled" Value="false">
diff --git a/VECTO3GUI2020/VECTO3GUI2020.csproj b/VECTO3GUI2020/VECTO3GUI2020.csproj
index a96bb060f6..80fb39c755 100644
--- a/VECTO3GUI2020/VECTO3GUI2020.csproj
+++ b/VECTO3GUI2020/VECTO3GUI2020.csproj
@@ -77,6 +77,9 @@
     <Reference Include="Microsoft.WindowsAPICodePack.Shell, Version=1.1.0.0, Culture=neutral, processorArchitecture=MSIL">
       <HintPath>..\packages\WindowsAPICodePack-Shell.1.1.1\lib\Microsoft.WindowsAPICodePack.Shell.dll</HintPath>
     </Reference>
+    <Reference Include="Microsoft.Xaml.Behaviors, Version=1.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
+      <HintPath>..\packages\Microsoft.Xaml.Behaviors.Wpf.1.1.31\lib\net45\Microsoft.Xaml.Behaviors.dll</HintPath>
+    </Reference>
     <Reference Include="Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
       <HintPath>..\packages\Newtonsoft.Json.12.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
     </Reference>
@@ -151,6 +154,7 @@
       <Generator>MSBuild:Compile</Generator>
       <SubType>Designer</SubType>
     </ApplicationDefinition>
+    <Compile Include="Behaviours\AutoScrollDataGridBehaviour.cs" />
     <Compile Include="Helper\ConvertedSIDummyCreator.cs" />
     <Compile Include="Helper\Converter\AlwaysVisibleConverter.cs" />
     <Compile Include="Helper\Converter\BoolToVisibilityConverter.cs" />
diff --git a/VECTO3GUI2020/Views/OutputView.xaml b/VECTO3GUI2020/Views/OutputView.xaml
index dae0431516..c5aa6cbbbb 100644
--- a/VECTO3GUI2020/Views/OutputView.xaml
+++ b/VECTO3GUI2020/Views/OutputView.xaml
@@ -3,11 +3,12 @@
              xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
              xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
              xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
-             xmlns:local="clr-namespace:VECTO3GUI2020.Views"
              xmlns:impl="clr-namespace:VECTO3GUI2020.ViewModel.Implementation"
-             xmlns:viewModel="clr-namespace:VECTO3GUI2020.ViewModel"
              mc:Ignorable="d" 
-             d:DesignHeight="450" d:DesignWidth="800" d:DataContext="{d:DesignData Type=viewModel:IOutputViewModel}">
+             d:DesignHeight="450" d:DesignWidth="800" d:DataContext="{d:DesignData Type=viewModel:IOutputViewModel}"
+             xmlns:behavior="clr-namespace:VECTO3GUI2020.Behaviours"
+             xmlns:i="http://schemas.microsoft.com/xaml/behaviors">
+
     <Grid>
         <DockPanel LastChildFill="False">
             <ProgressBar DockPanel.Dock="Top" 
@@ -29,7 +30,14 @@
                 IsReadOnly="True" 
                 HeadersVisibility="All"  
                 RowHeaderWidth="5" 
-                Name="MessageList">
+                Name="MessageList"
+                ColumnHeaderStyle="{StaticResource JobListDataGridHeaderStyle}"
+                ColumnHeaderHeight="30"
+            >
+                <i:Interaction.Behaviors>
+                    <behavior:AutoScrollDataGridBehaviour>
+                    </behavior:AutoScrollDataGridBehaviour>
+                </i:Interaction.Behaviors>
                 <DataGrid.Columns>
                         <DataGridTemplateColumn Header="Message" Width="*">
                             <DataGridTemplateColumn.CellTemplate>
@@ -55,10 +63,10 @@
                                 </DataTemplate>
                             </DataGridTemplateColumn.CellTemplate>
                         </DataGridTemplateColumn>
-                        <DataGridTextColumn Header="Time" Binding="{Binding Time}" Width="130" />
+                        <DataGridTextColumn Header="Time" Binding="{Binding Time, StringFormat=hh:mm:ss dd.MM.yyyy}" Width="150" />
                     </DataGrid.Columns>
                 <DataGrid.RowStyle>
-                    <Style TargetType="DataGridRow">
+                    <Style TargetType="DataGridRow">                   
                         <Style.Triggers>
                             <DataTrigger Binding="{Binding Type}" Value="{x:Static impl:MessageType.StatusMessage}">
                                 <Setter Property="Background" Value="AliceBlue"/>
@@ -67,7 +75,7 @@
                                 <Setter Property="Background" Value="LemonChiffon"/>
                             </DataTrigger>
                             <DataTrigger Binding="{Binding Type}" Value="{x:Static impl:MessageType.ErrorMessage}">
-                                <Setter Property="Background" Value="Red"/>
+                                <Setter Property="Background" Value="OrangeRed"/>
                             </DataTrigger>
                             <DataTrigger Binding="{Binding Type}" Value="{x:Static impl:MessageType.WarningMessage}">
                                 <Setter Property="Background" Value="Gold"/>
@@ -76,7 +84,7 @@
                     </Style>
                 </DataGrid.RowStyle>
                 <DataGrid.CellStyle>
-                    <Style TargetType="DataGridCell">
+                    <Style TargetType="DataGridCell" BasedOn="{StaticResource DataGridCellStyle1}">
                         <Setter Property="FontFamily" Value="Courier New"/>
                         <Style.Triggers>
                             <DataTrigger Binding="{Binding Type}" Value="{x:Static impl:MessageType.StatusMessage}">
diff --git a/VECTO3GUI2020/Views/OutputView.xaml.cs b/VECTO3GUI2020/Views/OutputView.xaml.cs
index c9eab7dc56..f07ca73a6f 100644
--- a/VECTO3GUI2020/Views/OutputView.xaml.cs
+++ b/VECTO3GUI2020/Views/OutputView.xaml.cs
@@ -24,5 +24,6 @@ namespace VECTO3GUI2020.Views
         {
             InitializeComponent();
         }
-    }
+
+	}
 }
diff --git a/VECTO3GUI2020/packages.config b/VECTO3GUI2020/packages.config
index 97e7978a0c..0a9c7181c7 100644
--- a/VECTO3GUI2020/packages.config
+++ b/VECTO3GUI2020/packages.config
@@ -5,6 +5,7 @@
   <package id="Microsoft.Bcl.AsyncInterfaces" version="5.0.0" targetFramework="net48" />
   <package id="Microsoft.Maps.MapControl.WPF" version="1.0.0.3" targetFramework="net48" />
   <package id="Microsoft.Toolkit.Mvvm" version="7.0.2" targetFramework="net48" />
+  <package id="Microsoft.Xaml.Behaviors.Wpf" version="1.1.31" targetFramework="net48" />
   <package id="Newtonsoft.Json" version="12.0.1" targetFramework="net48" />
   <package id="Ninject" version="3.3.4" targetFramework="net48" />
   <package id="Ninject.Extensions.ChildKernel" version="3.3.0" targetFramework="net48" />
diff --git a/Vecto3GUI2020Test/TestData/output/exempted_primary_heavyBus.vsum b/Vecto3GUI2020Test/TestData/output/exempted_primary_heavyBus.vsum
new file mode 100644
index 0000000000..453011a4cd
--- /dev/null
+++ b/Vecto3GUI2020Test/TestData/output/exempted_primary_heavyBus.vsum
@@ -0,0 +1,3 @@
+# VECTO-DEV 0.7.3.2247-DEV - 21.06.2021 10:30
+Job [-],Input File [-],Cycle [-],Status,Vehicle manufacturer [-],VIN number,Vehicle model [-],HDV CO2 vehicle class [-],Corrected Actual Curb Mass [kg],Loading [kg],Passenger count [-],Total vehicle mass [kg],Engine manufacturer [-],Engine model [-],Engine fuel type [-],Engine rated power [kW],Engine idling speed [rpm],Engine rated speed [rpm],Engine displacement [ccm],Engine WHTCUrban,Engine WHTCRural,Engine WHTCMotorway,Engine BFColdHot,Engine CFRegPer,Engine actual CF,Vehicle fuel type [-],AirDrag model [-],Declared CdxA [m²],CdxA [m²],Sleeper cab [-],Declared RRC axle 1 [-],Declared FzISO axle 1 [N],Declared RRC axle 2 [-],Declared FzISO axle 2 [N],Declared RRC axle 3 [-],Declared FzISO axle 3 [N],Declared RRC axle 4 [-],Declared FzISO axle 4 [N],total RRC [-],weighted RRC w/o trailer [-],r_dyn [m],Number axles vehicle driven [-],Number axles vehicle non-driven [-],Number axles trailer [-],Gearbox manufacturer [-],Gearbox model [-],Gearbox type [-],Gear ratio first gear [-],Gear ratio last gear [-],Torque converter manufacturer [-],Torque converter model [-],Retarder manufacturer [-],Retarder model [-],Retarder type [-],Angledrive manufacturer [-],Angledrive model [-],Angledrive ratio [-],Axle manufacturer [-],Axle model [-],Axle gear ratio [-],Auxiliary technology STP [-],Auxiliary technology FAN [-],Auxiliary technology AC [-],Auxiliary technology PS [-],Auxiliary technology ES [-],ShiftStrategy,ADAS technology combination [-],PTOShaftsGearWheels,REESS Capacity,Cargo Volume [m³],time [s],distance [km],speed [km/h],altitudeDelta [m],CO2 [g/km],CO2 [g/tkm],CO2 [g/m³km],CO2 [g/Pkm],P_wheel_in [kW],P_wheel_in_pos [kW],P_fcmap [kW],P_fcmap_pos [kW],E_fcmap_pos [kWh],E_fcmap_neg [kWh],E_powertrain_inertia [kWh],E_aux_sum [kWh],E_aux_el(HV) [kWh],E_clutch_loss [kWh],E_tc_loss [kWh],E_shift_loss [kWh],E_gbx_loss [kWh],E_ret_loss [kWh],E_angle_loss [kWh],E_axl_loss [kWh],E_brake [kWh],E_vehi_inertia [kWh],E_air [kWh],E_roll [kWh],E_grad [kWh],BusAux PS air consumed [Nl],BusAux PS air generated [Nl],E_PS_compressorOff [kWh],E_PS_compressorOn [kWh],E_BusAux_ES_consumed [kWh],E_BusAux_ES_generated [kWh],ΔE_BusAux_Bat [kWh],E_BusAux_PS_corr [kWh],E_BusAux_ES_mech_corr [kWh],E_BusAux_HVAC_mech [kWh],E_BusAux_HVAC_el [kWh],E_BusAux_AuxhHeater [kWh],E_WHR_el [kWh],E_WHR_mech [kWh],E_ice_start [kWh],ice_starts [-],a [m/s^2],a_pos [m/s^2],a_neg [m/s^2],AccelerationTimeShare [%],DecelerationTimeShare [%],CruiseTimeShare [%],max. speed [km/h],max. acc [m/s²],max. dec [m/s²],n_eng_avg [rpm],n_eng_max [rpm],gear shifts [-],StopTimeShare [%],ICE max. Load time share [%],ICE off time share [%],CoastingTimeShare [%],BrakingTimeShare [%],a_avg_acc,Engine certification number,Average engine efficiency [-],Torque converter certification option,TorqueConverter certification number,Average torque converter efficiency w/o lockup [-],Average torque converter efficiency with lockup [-],Gearbox certification option,Gearbox certification number,Average gearbox efficiency [-],Retarder certification option,Retarder certification number,Angledrive certification option,Angledrive certification number,Average angledrive efficiency [-],Axlegear certification method,Axlegear certification number,Average axlegear efficiency [-],AirDrag certification number,AirDrag certification option
+#@ SHA256: 7vbPy9Jy6A6bdZ7rFwmcXuHwiZ2ETwpcc8ZwxJGvJNs=
-- 
GitLab