Skip to content

Portable Tool for an Ideal Windows Setup

add StateNA dependency property for ToggleButton

Greedeks35bb9dba2421
diff --git a/.Source/GTweak/Assets/UserControl/ToggleButton.xaml.cs b/.Source/GTweak/Assets/UserControl/ToggleButton.xaml.cs
index 6a101911..e999de74 100644
--- a/.Source/GTweak/Assets/UserControl/ToggleButton.xaml.cs
+++ b/.Source/GTweak/Assets/UserControl/ToggleButton.xaml.cs
@@ -19,14 +19,34 @@ namespace GTweak.Assets.UserControl
private readonly LinearGradientBrush brushOffColor = new LinearGradientBrush(), brushOnColor = new LinearGradientBrush();
private bool _state = false;
private readonly Thickness _leftPosition = new Thickness(4, 0, 0, 0), _rightPosition = new Thickness(42, 0, 0, 0);
+
/// <summary>
/// Changes the state of a Toggle Button with animation
/// </summary>
internal bool State { get => _state; set { _state = value; UpdateToggleState(_state); } }
+
/// <summary>
/// Changes the state of a ToggleButton without animation
/// </summary>
- internal bool StateNA { get => _state; set { _state = value; UpdateToggleState(_state, true); } }
+ internal bool StateNA
+ {
+ get => (bool)GetValue(StateNAProperty);
+ set => SetValue(StateNAProperty, value);
+ }
+
+ /// <summary>
+ /// Dependency property used for binding without triggering animations
+ /// </summary>
+ internal static readonly DependencyProperty StateNAProperty = DependencyProperty.Register(nameof(StateNA), typeof(bool), typeof(ToggleButton), new PropertyMetadata(false, (d, e) =>
+ {
+ if (d is ToggleButton tbtn)
+ {
+ bool newValue = (bool)e.NewValue;
+ tbtn._state = newValue;
+ tbtn.UpdateToggleState(newValue, true);
+ }
+ }));
+
/// <summary>
/// Changes the text for ToggleButton. Accepts: Dynamic and Static Resource, just a string.
/// </summary>
diff --git a/.Source/GTweak/Core/ViewModel/MainViewModel.cs b/.Source/GTweak/Core/ViewModel/MainViewModel.cs
index df4005a7..9a68f94d 100644
--- a/.Source/GTweak/Core/ViewModel/MainViewModel.cs
+++ b/.Source/GTweak/Core/ViewModel/MainViewModel.cs
@@ -33,6 +33,16 @@ namespace GTweak.Core.ViewModel
public string DisplayTweakVersion => (Assembly.GetEntryAssembly() ?? throw new InvalidOperationException()).GetCustomAttribute<AssemblyInformationalVersionAttribute>().InformationalVersion;
+ public bool IsViewNotification => SettingsEngine.IsViewNotification;
+
+ public bool IsUpdateCheckRequired => SettingsEngine.IsUpdateCheckRequired;
+
+ public bool IsTopMost => SettingsEngine.IsTopMost;
+
+ public bool IsPlayingSound => SettingsEngine.IsPlayingSound;
+
+ public int CurrentVolume => SettingsEngine.Volume;
+
public string SelectedLanguage
{
get => _model.SelectedLanguage;
diff --git a/.Source/GTweak/Windows/MainWindow.xaml b/.Source/GTweak/Windows/MainWindow.xaml
index 13871b50..7b7250de 100644
--- a/.Source/GTweak/Windows/MainWindow.xaml
+++ b/.Source/GTweak/Windows/MainWindow.xaml
@@ -12,7 +12,7 @@
Title="GTweak"
Height="630" Width="1100" MinHeight="630" MinWidth="1100" ResizeMode="NoResize" WindowStyle="None" Background="Transparent"
AllowsTransparency="True" WindowStartupLocation="CenterScreen" SnapsToDevicePixels="True" UseLayoutRounding="True"
- Closing="Window_Closing" Loaded="Window_Loaded" WindowChrome.IsHitTestVisibleInChrome="False">
+ Closing="Window_Closing" Loaded="Window_Loaded" WindowChrome.IsHitTestVisibleInChrome="False" Topmost="{Binding IsTopMost, Mode=OneWay}">
<Window.DataContext>
<vm:MainViewModel/>
</Window.DataContext>
@@ -225,16 +225,16 @@
<Grid Grid.Row="1">
<StackPanel Orientation="Vertical">
- <uс:ToggleButton x:Name="BtnNotification" TextResource="{DynamicResource btgl_notifications_main}" VerticalAlignment="Top" Height="25" Margin="40,20,0,0" ChangedState="BtnNotification_ChangedState"/>
+ <uс:ToggleButton x:Name="BtnNotification" StateNA="{Binding IsViewNotification}" TextResource="{DynamicResource btgl_notifications_main}" VerticalAlignment="Top" Height="25" Margin="40,20,0,0" ChangedState="BtnNotification_ChangedState"/>
- <uс:ToggleButton x:Name="BtnUpdate" TextResource="{DynamicResource btgl_update_main}" VerticalAlignment="Top" Height="25" Margin="40,15,0,0" ChangedState="BtnUpdate_ChangedState"/>
+ <uс:ToggleButton x:Name="BtnUpdate" StateNA="{Binding IsUpdateCheckRequired}" TextResource="{DynamicResource btgl_update_main}" VerticalAlignment="Top" Height="25" Margin="40,15,0,0" ChangedState="BtnUpdate_ChangedState"/>
- <uс:ToggleButton x:Name="BtnTopMost" VerticalAlignment="Top" Height="25" TextResource="{DynamicResource btgl_toast_main}" Margin="40,15,0,0" ChangedState="BtnTopMost_ChangedState"/>
+ <uс:ToggleButton x:Name="BtnTopMost" StateNA="{Binding IsTopMost}" VerticalAlignment="Top" Height="25" TextResource="{DynamicResource btgl_toast_main}" Margin="40,15,0,0" ChangedState="BtnTopMost_ChangedState"/>
<StackPanel Orientation="Horizontal" Height="45" VerticalAlignment="Top" Margin="40,10,0,0">
<TextBlock Style="{StaticResource Text_In}" Foreground="{StaticResource Color_Highlighted}" Margin="0,4,0,0" Text="{DynamicResource slider_volume_main}"/>
- <ToggleButton x:Name="BtnSoundNtn" Width="20" Height="20" Margin="10,1,0,0" Style="{StaticResource TglButtonSound}" PreviewMouseLeftButtonUp="BtnSoundNtn_PreviewMouseLeftButtonUp"/>
- <Slider x:Name="SliderVolume" Style="{StaticResource HorizontalText_Slider}" IsSnapToTickEnabled="True" Minimum="0" Maximum="100" Margin="10,4,0,0" Width="187" ValueChanged="SliderVolume_ValueChanged" Height="10"/>
+ <ToggleButton x:Name="BtnSoundNtn" IsChecked="{Binding IsPlayingSound, Mode=OneWay}" Width="20" Height="20" Margin="10,1,0,0" Style="{StaticResource TglButtonSound}" PreviewMouseLeftButtonUp="BtnSoundNtn_PreviewMouseLeftButtonUp"/>
+ <Slider x:Name="SliderVolume" Value="{Binding CurrentVolume, Mode=OneWay}" Style="{StaticResource HorizontalText_Slider}" IsSnapToTickEnabled="True" Minimum="0" Maximum="100" Margin="10,4,0,0" Width="187" ValueChanged="SliderVolume_ValueChanged" Height="10"/>
</StackPanel>
<StackPanel Orientation="Horizontal" Height="45" VerticalAlignment="Top" Margin="40,10,0,0">
diff --git a/.Source/GTweak/Windows/MainWindow.xaml.cs b/.Source/GTweak/Windows/MainWindow.xaml.cs
index 765c2dae..752be98f 100644
--- a/.Source/GTweak/Windows/MainWindow.xaml.cs
+++ b/.Source/GTweak/Windows/MainWindow.xaml.cs
@@ -19,12 +19,6 @@ namespace GTweak
{
InitializeComponent();
- BtnNotification.StateNA = SettingsEngine.IsViewNotification;
- BtnUpdate.StateNA = SettingsEngine.IsUpdateCheckRequired;
- BtnTopMost.StateNA = Topmost = SettingsEngine.IsTopMost;
- BtnSoundNtn.IsChecked = SettingsEngine.IsPlayingSound;
- SliderVolume.Value = SettingsEngine.Volume;
-
App.TweaksImported += delegate { BtnMore.IsChecked = true; };
App.ThemeChanged += delegate { Close(); new RebootWindow().ShowDialog(); };
}
@@ -94,11 +88,7 @@ namespace GTweak
private void BtnUpdate_ChangedState(object sender, EventArgs e) => SettingsEngine.IsUpdateCheckRequired = !BtnUpdate.State;
- private void BtnTopMost_ChangedState(object sender, EventArgs e)
- {
- SettingsEngine.IsTopMost = !BtnTopMost.State;
- Topmost = !BtnTopMost.State;
- }
+ private void BtnTopMost_ChangedState(object sender, EventArgs e) => SettingsEngine.IsTopMost = Topmost = !BtnTopMost.State;
private void BtnSoundNtn_PreviewMouseLeftButtonUp(object sender, MouseButtonEventArgs e) => SettingsEngine.IsPlayingSound = (bool)!BtnSoundNtn.IsChecked;