-
Notifications
You must be signed in to change notification settings - Fork 6.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Settings][Chore] Add CheckBoxWithDescriptionControl (#13866)
* Added new control * Update Microsoft.PowerToys.Settings.UI.csproj * Added styling * Add enableableTextBlock * Update EnableableTextBlock.xaml * Updated styles * Updates styles * Updated margins * Name change and typo fix * Update App.xaml * Control name change * Update expect.txt * More name changes * Even more name changes Co-authored-by: Laute <Niels.Laute@philips.com>
- Loading branch information
Showing
12 changed files
with
194 additions
and
128 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
src/settings-ui/Microsoft.PowerToys.Settings.UI/Controls/CheckBoxWithDescriptionControl.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// Copyright (c) Microsoft Corporation | ||
// The Microsoft Corporation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System.ComponentModel; | ||
using Windows.UI.Accessibility; | ||
using Windows.UI.Xaml; | ||
using Windows.UI.Xaml.Automation; | ||
using Windows.UI.Xaml.Controls; | ||
using Windows.UI.Xaml.Media; | ||
|
||
namespace Microsoft.PowerToys.Settings.UI.Controls | ||
{ | ||
public class CheckBoxWithDescriptionControl : CheckBox | ||
{ | ||
private CheckBoxWithDescriptionControl _checkBoxSubTextControl; | ||
|
||
public CheckBoxWithDescriptionControl() | ||
{ | ||
_checkBoxSubTextControl = (CheckBoxWithDescriptionControl)this; | ||
this.Loaded += CheckBoxSubTextControl_Loaded; | ||
} | ||
|
||
protected override void OnApplyTemplate() | ||
{ | ||
Update(); | ||
base.OnApplyTemplate(); | ||
} | ||
|
||
private void Update() | ||
{ | ||
if (!string.IsNullOrEmpty(Header)) | ||
{ | ||
AutomationProperties.SetName(this, Header); | ||
} | ||
} | ||
|
||
private void CheckBoxSubTextControl_Loaded(object sender, RoutedEventArgs e) | ||
{ | ||
StackPanel panel = new StackPanel() { Orientation = Orientation.Vertical }; | ||
panel.Children.Add(new TextBlock() { Margin = new Thickness(0, 10, 0, 0), Text = Header }); | ||
panel.Children.Add(new IsEnabledTextBlock() { FontSize = (double)App.Current.Resources["SecondaryTextFontSize"], Foreground = (SolidColorBrush)App.Current.Resources["TextFillColorSecondaryBrush"], Text = Description }); | ||
_checkBoxSubTextControl.Content = panel; | ||
} | ||
|
||
public static readonly DependencyProperty HeaderProperty = DependencyProperty.Register( | ||
"Header", | ||
typeof(string), | ||
typeof(CheckBoxWithDescriptionControl), | ||
new PropertyMetadata(default(string))); | ||
|
||
public static readonly DependencyProperty DescriptionProperty = DependencyProperty.Register( | ||
"Description", | ||
typeof(object), | ||
typeof(CheckBoxWithDescriptionControl), | ||
new PropertyMetadata(default(string))); | ||
|
||
[Localizable(true)] | ||
public string Header | ||
{ | ||
get => (string)GetValue(HeaderProperty); | ||
set => SetValue(HeaderProperty, value); | ||
} | ||
|
||
[Localizable(true)] | ||
public string Description | ||
{ | ||
get => (string)GetValue(DescriptionProperty); | ||
set => SetValue(DescriptionProperty, value); | ||
} | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
...ings-ui/Microsoft.PowerToys.Settings.UI/Controls/IsEnabledTextBlock/IsEnabledTextBlock.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// Copyright (c) Microsoft Corporation | ||
// The Microsoft Corporation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System.ComponentModel; | ||
using Windows.UI.Xaml; | ||
using Windows.UI.Xaml.Controls; | ||
|
||
namespace Microsoft.PowerToys.Settings.UI.Controls | ||
{ | ||
[TemplateVisualState(Name = "Normal", GroupName = "CommonStates")] | ||
[TemplateVisualState(Name = "Disabled", GroupName = "CommonStates")] | ||
public class IsEnabledTextBlock : Control | ||
{ | ||
public IsEnabledTextBlock() | ||
{ | ||
this.DefaultStyleKey = typeof(IsEnabledTextBlock); | ||
} | ||
|
||
protected override void OnApplyTemplate() | ||
{ | ||
IsEnabledChanged -= IsEnabledTextBlock_IsEnabledChanged; | ||
SetEnabledState(); | ||
IsEnabledChanged += IsEnabledTextBlock_IsEnabledChanged; | ||
base.OnApplyTemplate(); | ||
} | ||
|
||
public static readonly DependencyProperty TextProperty = DependencyProperty.Register( | ||
"Text", | ||
typeof(string), | ||
typeof(IsEnabledTextBlock), | ||
null); | ||
|
||
[Localizable(true)] | ||
public string Text | ||
{ | ||
get => (string)GetValue(TextProperty); | ||
set => SetValue(TextProperty, value); | ||
} | ||
|
||
private void IsEnabledTextBlock_IsEnabledChanged(object sender, DependencyPropertyChangedEventArgs e) | ||
{ | ||
SetEnabledState(); | ||
} | ||
|
||
private void SetEnabledState() | ||
{ | ||
VisualStateManager.GoToState(this, IsEnabled ? "Normal" : "Disabled", true); | ||
} | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
...gs-ui/Microsoft.PowerToys.Settings.UI/Controls/IsEnabledTextBlock/IsEnabledTextBlock.xaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<ResourceDictionary | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:local="using:Microsoft.PowerToys.Settings.UI.Controls"> | ||
|
||
<Style TargetType="local:IsEnabledTextBlock"> | ||
<Setter Property="Foreground" Value="{ThemeResource DefaultTextForegroundThemeBrush}" /> | ||
<Setter Property="Template"> | ||
<Setter.Value> | ||
<ControlTemplate TargetType="local:IsEnabledTextBlock"> | ||
<Grid> | ||
<VisualStateManager.VisualStateGroups> | ||
<VisualStateGroup x:Name="CommonStates"> | ||
<VisualState x:Name="Normal"/> | ||
<VisualState x:Name="Disabled"> | ||
<VisualState.Setters> | ||
<Setter Target="Label.Foreground" Value="{ThemeResource TextFillColorDisabledBrush}" /> | ||
</VisualState.Setters> | ||
</VisualState> | ||
</VisualStateGroup> | ||
</VisualStateManager.VisualStateGroups> | ||
<TextBlock x:Name="Label" | ||
FontSize="{TemplateBinding FontSize}" | ||
FontWeight="{TemplateBinding FontWeight}" | ||
FontFamily="{TemplateBinding FontFamily}" | ||
Foreground="{TemplateBinding Foreground}" | ||
TextWrapping="WrapWholeWords" | ||
Text="{TemplateBinding Text}" /> | ||
</Grid> | ||
</ControlTemplate> | ||
</Setter.Value> | ||
</Setter> | ||
</Style> | ||
</ResourceDictionary> |
15 changes: 0 additions & 15 deletions
15
src/settings-ui/Microsoft.PowerToys.Settings.UI/Controls/TextBlockControl.xaml
This file was deleted.
Oops, something went wrong.
76 changes: 0 additions & 76 deletions
76
src/settings-ui/Microsoft.PowerToys.Settings.UI/Controls/TextBlockControl.xaml.cs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.