Skip to content

Commit

Permalink
Merge pull request #30 from F1Telemetry/F-24
Browse files Browse the repository at this point in the history
♻️ F-24 Update Tyre module to use only one DataGrid
  • Loading branch information
ryanabaker committed Feb 19, 2022
2 parents 01a14f3 + eafb078 commit ecb22b8
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 51 deletions.
1 change: 1 addition & 0 deletions F1T/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<ResourceDictionary Source="./Themes/ComboBoxTheme.xaml"></ResourceDictionary>
<ResourceDictionary Source="./Themes/SocialButtonTheme.xaml"></ResourceDictionary>
<ResourceDictionary Source="./Themes/ButtonTheme.xaml"></ResourceDictionary>
<ResourceDictionary Source="./Themes/DataGridTheme.xaml"></ResourceDictionary>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
Expand Down
27 changes: 27 additions & 0 deletions F1T/Core/BindingProxy.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System.Windows;

namespace F1T.Core
{
// https://stackoverflow.com/questions/22073740/binding-visibility-for-datagridcolumn-in-wpf
public class BindingProxy : Freezable
{
#region Overrides of Freezable

protected override Freezable CreateInstanceCore()
{
return new BindingProxy();
}

#endregion

public object Data
{
get { return (object)GetValue(DataProperty); }
set { SetValue(DataProperty, value); }
}

public static readonly DependencyProperty DataProperty =
DependencyProperty.Register("Data", typeof(object),
typeof(BindingProxy));
}
}
5 changes: 5 additions & 0 deletions F1T/F1T.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@
<Compile Include="Converters\SteeringConverter.cs" />
<Compile Include="Converters\StringToImageConverter.cs" />
<Compile Include="Converters\ToggledColorConverter.cs" />
<Compile Include="Core\BindingProxy.cs" />
<Compile Include="Core\FocusMonitor.cs" />
<Compile Include="Core\ObservableObject.cs" />
<Compile Include="Core\RelayCommand.cs" />
Expand Down Expand Up @@ -276,6 +277,10 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Themes\DataGridTheme.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Themes\PercentageSliderTheme.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
Expand Down
68 changes: 17 additions & 51 deletions F1T/MVVM/Views/Tyre/TyreOverlayView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,70 +8,36 @@
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:F1T.MVVM.Views.Tyre" xmlns:converters="clr-namespace:F1T.Converters"
xmlns:local="clr-namespace:F1T.MVVM.Views.Tyre" xmlns:converters="clr-namespace:F1T.Converters" xmlns:core="clr-namespace:F1T.Core"
mc:Ignorable="d"
Background="Transparent"
MouseDown="Window_MouseDown" Height="125">

<UserControl.Resources>

<converters:BoolToVisConverter x:Key="BoolToVisConverter"/>


<Style TargetType="{x:Type DataGrid}">
<Setter Property="Background" Value="Transparent" />
<Setter Property="AlternationCount" Value="2" />
<Setter Property="BorderThickness" Value="0"/>
</Style>

<Style TargetType="{x:Type DataGridRow}">
<Setter Property="IsHitTestVisible" Value="False"/>
<Setter Property="Foreground" Value="White" />
<Setter Property="Background" Value="Transparent" />
</Style>


<Style TargetType="{x:Type DataGridColumnHeader}">
<Setter Property="Height" Value="35" />
<Setter Property="Padding" Value="5" />
<Setter Property="Background" Value="Transparent" />
<Setter Property="Foreground" Value="White" />
<Setter Property="FontFamily" Value="/Fonts/#Poppins" />
<Setter Property="FontWeight" Value="Medium" />
<Setter Property="BorderThickness" Value="0"/>
<Setter Property="IsHitTestVisible" Value="False"/>
</Style>
</UserControl.Resources>

<Grid MouseDown="Window_MouseDown">

<Rectangle Fill="Black" Opacity="{Binding Path=Settings.Opacity}"></Rectangle>

<Grid.ColumnDefinitions>
<ColumnDefinition></ColumnDefinition>
<ColumnDefinition></ColumnDefinition>
</Grid.ColumnDefinitions>


<Rectangle Fill="Black" Opacity="{Binding Path=Settings.Opacity}" Grid.ColumnSpan="2"></Rectangle>

<DataGrid Grid.Column="0" Visibility="{Binding Settings.TyreWearVisible, Converter={StaticResource BoolToVisConverter}}"
ItemsSource="{Binding Path=TyreInfoArr}" IsReadOnly="True"
<DataGrid ItemsSource="{Binding Path=TyreInfoArr}" IsReadOnly="True"
AutoGenerateColumns="False" RowHeaderWidth="0" MouseDown="Window_MouseDown"
GridLinesVisibility="None">
GridLinesVisibility="None"
Style="{StaticResource DataGridTheme}">
<DataGrid.Resources>
<core:BindingProxy x:Key="proxy" Data="{Binding Settings}"/>
</DataGrid.Resources>
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding TyreWear, StringFormat='{}{0}%'}" Header="Wear"/>
<DataGridTextColumn Binding="{Binding TyreWear, StringFormat='{}{0}%'}" Header="Wear"
Visibility="{Binding Data.TyreWearVisible,
Converter={StaticResource BoolToVisConverter},
Source={StaticResource proxy}}"/>
<DataGridTextColumn Binding="{Binding TyreAge, StringFormat='{}{0}L'}" Header="Laps"
Visibility="{Binding Data.TyreAgeVisible,
Converter={StaticResource BoolToVisConverter},
Source={StaticResource proxy}}"/>
</DataGrid.Columns>
</DataGrid>

<DataGrid Grid.Column="1" Visibility="{Binding Settings.TyreAgeVisible, Converter={StaticResource BoolToVisConverter}}"
ItemsSource="{Binding Path=TyreInfoArr}" IsReadOnly="True"
AutoGenerateColumns="False" RowHeaderWidth="0" MouseDown="Window_MouseDown"
GridLinesVisibility="None">
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding TyreAge, StringFormat='{}{0}L'}" Header="Laps"/>
</DataGrid.Columns>
</DataGrid>



</Grid>
</src:BaseOverlayView>
26 changes: 26 additions & 0 deletions F1T/Themes/DataGridTheme.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

<Style x:Key="DataGridTheme" TargetType="{x:Type DataGrid}">
<Setter Property="Background" Value="Transparent" />
<Setter Property="AlternationCount" Value="2" />
<Setter Property="BorderThickness" Value="0"/>
</Style>

<Style TargetType="{x:Type DataGridRow}">
<Setter Property="IsHitTestVisible" Value="False"/>
<Setter Property="Foreground" Value="White" />
<Setter Property="Background" Value="Transparent" />
</Style>

<Style TargetType="{x:Type DataGridColumnHeader}">
<Setter Property="Height" Value="35" />
<Setter Property="Padding" Value="5" />
<Setter Property="Background" Value="Transparent" />
<Setter Property="Foreground" Value="White" />
<Setter Property="FontFamily" Value="/Fonts/#Poppins" />
<Setter Property="FontWeight" Value="Medium" />
<Setter Property="BorderThickness" Value="0"/>
<Setter Property="IsHitTestVisible" Value="False"/>
</Style>
</ResourceDictionary>

0 comments on commit ecb22b8

Please sign in to comment.