Skip to content

Commit

Permalink
Fix some button hovers causing crash
Browse files Browse the repository at this point in the history
Don't know why I was trying to get children when the WPF way of doing it worked just fine...
  • Loading branch information
TCNOco committed Feb 29, 2020
1 parent 53f1c6d commit 146125f
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 45 deletions.
26 changes: 26 additions & 0 deletions TCNO-Acc-Switcher-CSharp-WPF/TCNO-Acc-Switcher-CSharp-WPF/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,32 @@
</Setter.Value>
</Setter>
</Style>

<!-- Pick Steam Folder button -->
<Style x:Key="mainMenuButtons" TargetType="Button">
<Setter Property="OverridesDefaultStyle" Value="True" />
<Setter Property="Cursor" Value="Hand" />
<Setter Property="Background" Value="#333333"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Border Name="border" Padding="5 0" BorderThickness="1.5" BorderBrush="Gray" Background="{TemplateBinding Background}">
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center" />
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="#444444"></Setter>
<Setter Property="BorderBrush" Value="#0685d1"></Setter>
</Trigger>
<Trigger Property="IsPressed" Value="True">
<Setter Property="Background" Value="#333333"></Setter>
<Setter Property="BorderBrush" Value="#808080"></Setter>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>

<!-- Header bar buttons -->
<Style x:Key="ExitButton" TargetType="Button">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -339,19 +339,19 @@
<!--<ProgressBar Grid.Row="2" HorizontalAlignment="Left" VerticalAlignment="Bottom" Margin="5px 0 0 0" Width="100px" Height="10px" Background="#333333" Foreground="White"/>-->
<DockPanel Panel.ZIndex="6" HorizontalAlignment="Right" Margin="0 5">
<Button Name="btnLogin" IsEnabled="False" Content="Login" HorizontalAlignment="Right" Grid.Row="2" Margin="5 0 5 0" VerticalAlignment="Center" Foreground="White" Style="{StaticResource LoginButton}" PreviewMouseDown="LoginMouseDown" MouseEnter="btnLogin_MouseEnter" MouseLeave="btnLogin_MouseLeave"/>
<Button BorderBrush="Gray" BorderThickness="1.5" Background="#333333" HorizontalAlignment="Right" Grid.Row="2" Width="34" Height="34" Margin="0 0 5 0" Name="chkShowSettings" MouseEnter="chkShowSettings_MouseEnter" MouseLeave="chkShowSettings_MouseLeave" Click="chkShowSettings_Click">
<Button BorderBrush="Gray" BorderThickness="1.5" HorizontalAlignment="Right" Grid.Row="2" Width="34" Height="34" Margin="0 0 5 0" Name="chkShowSettings" Click="chkShowSettings_Click" Style="{StaticResource mainMenuButtons}">
<Canvas xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" Name="svgsettings" Width="24" Height="24">
<Canvas.RenderTransform>
<TranslateTransform X="0" Y="0"/>
<TranslateTransform X="-1.5" Y="0"/>
</Canvas.RenderTransform>
<Canvas.Resources/>
<Path xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Name="path4" Fill="#FFFFFFFF" StrokeThickness="0.75" Data="M 21 13.212 V 10.788 C 19.76175 10.34775 18.9795 10.224 18.58575 9.27375 V 9.273 C 18.1905 8.31975 18.66075 7.6725 19.221 6.49275 L 17.50725 4.779 C 16.3365 5.3355 15.6825 5.81025 14.727 5.41425 h -7.5e-4 C 13.7745 5.01975 13.65 4.23225 13.212 3 H 10.788 C 10.3515 4.22625 10.22625 5.019 9.27375 5.41425 H 9.273 C 8.31975 5.81025 7.674 5.34075 6.49275 4.779 L 4.779 6.49275 C 5.33775 7.66875 5.81025 8.31825 5.41425 9.273 5.019 10.22625 4.22625 10.3515 3 10.788 v 2.424 c 1.224 0.435 2.019 0.56175 2.41425 1.51425 0.3975 0.9615 -0.0855 1.6245 -0.63525 2.78025 l 1.71375 1.7145 c 1.1715 -0.55725 1.8255 -1.03125 2.78025 -0.63525 h 7.5e-4 C 10.22625 18.98025 10.35075 19.77 10.788 21 h 2.424 c 0.4365 -1.227 0.5625 -2.0175 1.52025 -2.4165 h 7.5e-4 c 0.9465 -0.393 1.59 0.07575 2.7735 0.63825 l 1.71375 -1.7145 C 18.66225 16.335 18.189 15.6825 18.58425 14.72775 18.9795 13.7745 19.77525 13.64775 21 13.212 Z M 12 15 c -1.65675 0 -3 -1.34325 -3 -3 0 -1.65675 1.34325 -3 3 -3 1.65675 0 3 1.34325 3 3 0 1.65675 -1.34325 3 -3 3 z"/>
</Canvas>
</Button>
<Button BorderBrush="Gray" BorderThickness="1.5" Background="#333333" HorizontalAlignment="Right" Grid.Row="2" Width="34" Height="34" Margin="0 0 5 0" Name="btnShowInfo" MouseEnter="btnShowInfo_MouseEnter" MouseLeave="btnShowInfo_MouseLeave" Click="btnShowInfo_Click">
<Button BorderBrush="Gray" BorderThickness="1.5" HorizontalAlignment="Right" Grid.Row="2" Width="34" Height="34" Margin="0 0 5 0" Name="btnShowInfo" Click="btnShowInfo_Click" Style="{StaticResource mainMenuButtons}">
<Canvas xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" Name="svg4" Width="24" Height="24">
<Canvas.RenderTransform>
<TranslateTransform X="0" Y="0"/>
<TranslateTransform X="-1.5" Y="0"/>
</Canvas.RenderTransform>
<Canvas.Resources/>
<Path xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Name="path2" Fill="#FFFFFFFF" StrokeThickness="0.625" Data="m 13.625547 17.9375 c 0 0.8625 -0.6975 1.5625 -1.561875 1.5625 -0.86125 0 -1.561875 -0.7 -1.561875 -1.5625 0 -0.8625 0.700625 -1.5625 1.561875 -1.5625 0.864375 0 1.561875 0.699375 1.561875 1.5625 z M 12.113047 4.5 c -2.5181251 0 -4.4125001 1.683125 -4.4125001 5 h 2.4718751 c 0 -1.44 0.56625 -2.618125 1.89 -2.618125 0.779375 0 1.60625 0.5175 1.6775 1.506875 0.07687 1.04125 -0.479375 1.569375 -1.1825 2.23875 -1.8275 1.7375 -1.76 2.530625 -1.76 4.4975 h 2.464375 c 0 -0.9075 -0.09812 -1.5675 1.14875 -2.911875 0.831875 -0.8975 1.86625 -2.01375 1.888125 -3.714375 C 16.328047 6.021875 14.579297 4.5 12.113047 4.5 Z"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,31 +26,14 @@ namespace TCNO_Acc_Switcher_CSharp_WPF
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public static class getChild
{
public static T GetChildOfType<T>(this DependencyObject depObj)
where T : DependencyObject
{
if (depObj == null) return null;

for (int i = 0; i < VisualTreeHelper.GetChildrenCount(depObj); i++)
{
var child = VisualTreeHelper.GetChild(depObj, i);

var result = (child as T) ?? GetChildOfType<T>(child);
if (result != null) return result;
}
return null;
}
}
public partial class MainWindow : Window
{
List<Steamuser> userAccounts = new List<Steamuser>();
List<string> fLoginUsersLines = new List<string>();
MainWindowViewModel MainViewmodel = new MainWindowViewModel();

//int version = 1;
int version = 2301;
int version = 2302;
int trayversion = 1000;


Expand Down Expand Up @@ -1134,17 +1117,6 @@ private void Window_Closing(object sender, CancelEventArgs e)
saveSettings();
}

private void chkShowSettings_MouseEnter(object sender, MouseEventArgs e)
{
getChild.GetChildOfType<Border>(chkShowSettings).Background = new SolidColorBrush((Color)(ColorConverter.ConvertFromString("#444444")));
getChild.GetChildOfType<Border>(chkShowSettings).BorderBrush = new SolidColorBrush((Color)(ColorConverter.ConvertFromString("#0685d1")));
}

private void chkShowSettings_MouseLeave(object sender, MouseEventArgs e)
{
getChild.GetChildOfType<Border>(chkShowSettings).Background = new SolidColorBrush((Color)(ColorConverter.ConvertFromString("#333333")));
getChild.GetChildOfType<Border>(chkShowSettings).BorderBrush = new SolidColorBrush(Colors.Gray);
}
public void ResetSettings()
{
persistentSettings = new UserSettings();
Expand Down Expand Up @@ -1197,18 +1169,6 @@ private void Window_Closed(object sender, EventArgs e)
Environment.Exit(1);
}

private void btnShowInfo_MouseEnter(object sender, MouseEventArgs e)
{
getChild.GetChildOfType<Border>(btnShowInfo).Background = new SolidColorBrush((Color)(ColorConverter.ConvertFromString("#444444")));
getChild.GetChildOfType<Border>(btnShowInfo).BorderBrush = new SolidColorBrush((Color)(ColorConverter.ConvertFromString("#0685d1")));
}

private void btnShowInfo_MouseLeave(object sender, MouseEventArgs e)
{
getChild.GetChildOfType<Border>(btnShowInfo).Background = new SolidColorBrush((Color)(ColorConverter.ConvertFromString("#333333")));
getChild.GetChildOfType<Border>(btnShowInfo).BorderBrush = new SolidColorBrush(Colors.Gray);
}

private void btnShowInfo_Click(object sender, RoutedEventArgs e)
{
InfoWindow infoWindow = new InfoWindow();
Expand Down

0 comments on commit 146125f

Please sign in to comment.