-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from ghost1372/Wizard
Wizard
- Loading branch information
Showing
62 changed files
with
1,506 additions
and
1,687 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
127 changes: 127 additions & 0 deletions
127
VSIX/DevWinUI_Template/DevWinUI_Template/Controls/SettingsControl.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,127 @@ | ||
using System; | ||
using System.Windows; | ||
using System.Windows.Controls; | ||
using System.Windows.Markup; | ||
using Wpf.Ui.Controls; | ||
|
||
namespace DevWinUI_Template; | ||
|
||
[TemplatePart(Name = nameof(PART_ToggleSwitch), Type = typeof(ToggleSwitch))] | ||
[TemplatePart(Name = nameof(PART_Content), Type = typeof(ContentControl))] | ||
[ContentProperty(nameof(Item))] | ||
public class SettingsControl : Control | ||
{ | ||
private string PART_ToggleSwitch = "PART_ToggleSwitch"; | ||
private string PART_Content = "PART_Content"; | ||
private ToggleSwitch _ToggleSwitch; | ||
private ContentControl _ContentControl; | ||
|
||
public string Title | ||
{ | ||
get { return (string)GetValue(TitleProperty); } | ||
set { SetValue(TitleProperty, value); } | ||
} | ||
|
||
public static readonly DependencyProperty TitleProperty = | ||
DependencyProperty.Register(nameof(Title), typeof(string), typeof(SettingsControl), new PropertyMetadata(default(string))); | ||
|
||
public string Description | ||
{ | ||
get { return (string)GetValue(DescriptionProperty); } | ||
set { SetValue(DescriptionProperty, value); } | ||
} | ||
|
||
public static readonly DependencyProperty DescriptionProperty = | ||
DependencyProperty.Register(nameof(Description), typeof(string), typeof(SettingsControl), new PropertyMetadata(default(string))); | ||
|
||
public bool IsOn | ||
{ | ||
get { return (bool)GetValue(IsOnProperty); } | ||
set { SetValue(IsOnProperty, value); } | ||
} | ||
|
||
public static readonly DependencyProperty IsOnProperty = | ||
DependencyProperty.Register(nameof(IsOn), typeof(bool), typeof(SettingsControl), new PropertyMetadata(false)); | ||
|
||
public IconElement Icon | ||
{ | ||
get { return (IconElement)GetValue(IconProperty); } | ||
set { SetValue(IconProperty, value); } | ||
} | ||
|
||
public static readonly DependencyProperty IconProperty = | ||
DependencyProperty.Register(nameof(Icon), typeof(IconElement), typeof(SettingsControl), new PropertyMetadata(null)); | ||
public string OnContent | ||
{ | ||
get { return (string)GetValue(OnContentProperty); } | ||
set { SetValue(OnContentProperty, value); } | ||
} | ||
|
||
public static readonly DependencyProperty OnContentProperty = | ||
DependencyProperty.Register(nameof(OnContent), typeof(string), typeof(SettingsControl), new PropertyMetadata(default(string))); | ||
|
||
public string OffContent | ||
{ | ||
get { return (string)GetValue(OffContentProperty); } | ||
set { SetValue(OffContentProperty, value); } | ||
} | ||
|
||
public static readonly DependencyProperty OffContentProperty = | ||
DependencyProperty.Register(nameof(OffContent), typeof(string), typeof(SettingsControl), new PropertyMetadata(default(string))); | ||
|
||
public FrameworkElement Item | ||
{ | ||
get { return (FrameworkElement)GetValue(ItemProperty); } | ||
set { SetValue(ItemProperty, value); } | ||
} | ||
|
||
public static readonly DependencyProperty ItemProperty = | ||
DependencyProperty.Register(nameof(Item), typeof(FrameworkElement), typeof(SettingsControl), new PropertyMetadata(null, OnItemChanged)); | ||
|
||
private static void OnItemChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) | ||
{ | ||
var ctl = (SettingsControl)d; | ||
if (ctl != null) | ||
{ | ||
ctl.ChangeItemVisibility(); | ||
} | ||
} | ||
private void ChangeItemVisibility() | ||
{ | ||
if (_ToggleSwitch != null && _ContentControl != null) | ||
{ | ||
if (Item == null) | ||
{ | ||
_ContentControl.Visibility = Visibility.Collapsed; | ||
_ToggleSwitch.Visibility = Visibility.Visible; | ||
} | ||
else | ||
{ | ||
_ToggleSwitch.Visibility = Visibility.Collapsed; | ||
_ContentControl.Visibility = Visibility.Visible; | ||
} | ||
} | ||
} | ||
|
||
public event EventHandler<RoutedEventArgs> Toggled; | ||
|
||
public override void OnApplyTemplate() | ||
{ | ||
base.OnApplyTemplate(); | ||
_ToggleSwitch = GetTemplateChild(nameof(PART_ToggleSwitch)) as ToggleSwitch; | ||
_ContentControl = GetTemplateChild(nameof(PART_Content)) as ContentControl; | ||
if (_ToggleSwitch != null) | ||
{ | ||
_ToggleSwitch.Checked -= OnToggleChecked; | ||
_ToggleSwitch.Unchecked -= OnToggleChecked; | ||
_ToggleSwitch.Checked += OnToggleChecked; | ||
_ToggleSwitch.Unchecked += OnToggleChecked; | ||
} | ||
ChangeItemVisibility(); | ||
} | ||
|
||
private void OnToggleChecked(object sender, RoutedEventArgs e) | ||
{ | ||
Toggled?.Invoke(this, e); | ||
} | ||
} |
87 changes: 87 additions & 0 deletions
87
VSIX/DevWinUI_Template/DevWinUI_Template/Controls/SettingsControl.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,87 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:local="clr-namespace:DevWinUI_Template" | ||
xmlns:sys="clr-namespace:System;assembly=mscorlib" | ||
xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml"> | ||
|
||
<Style TargetType="local:SettingsControlWithExpander"> | ||
<Setter Property="Template"> | ||
<Setter.Value> | ||
<ControlTemplate TargetType="local:SettingsControlWithExpander"> | ||
<ui:CardExpander ContentPadding="0" | ||
Icon="{TemplateBinding Icon}" | ||
IsExpanded="{TemplateBinding IsExpanded}"> | ||
<ui:CardExpander.Header> | ||
<Grid> | ||
<Grid.RowDefinitions> | ||
<RowDefinition Height="Auto" /> | ||
<RowDefinition Height="Auto" /> | ||
</Grid.RowDefinitions> | ||
<Grid.ColumnDefinitions> | ||
<ColumnDefinition Width="*" /> | ||
<ColumnDefinition Width="Auto" /> | ||
</Grid.ColumnDefinitions> | ||
<ui:TextBlock Grid.Row="0" | ||
Grid.Column="0" | ||
FontTypography="Body" | ||
Text="{TemplateBinding Title}" /> | ||
<ui:TextBlock Grid.Row="1" | ||
Grid.Column="0" | ||
Foreground="{ui:ThemeResource TextFillColorSecondaryBrush}" | ||
Text="{TemplateBinding Description}" /> | ||
<ui:ToggleSwitch x:Name="PART_ToggleSwitch" | ||
Grid.Row="0" | ||
Grid.RowSpan="2" | ||
Grid.Column="1" | ||
Margin="0,0,16,0" | ||
VerticalAlignment="Center" | ||
Foreground="{ui:ThemeResource TextFillColorSecondaryBrush}" | ||
IsChecked="{TemplateBinding IsOn}" | ||
OffContent="Off" | ||
OnContent="On" /> | ||
</Grid> | ||
</ui:CardExpander.Header> | ||
<ContentControl Margin="0,5,0,10" | ||
Content="{TemplateBinding Item}" /> | ||
</ui:CardExpander> | ||
</ControlTemplate> | ||
</Setter.Value> | ||
</Setter> | ||
</Style> | ||
|
||
<Style TargetType="local:SettingsControl"> | ||
<Setter Property="Template"> | ||
<Setter.Value> | ||
<ControlTemplate TargetType="local:SettingsControl"> | ||
<ui:CardControl Margin="0,0,0,5" | ||
Icon="{TemplateBinding Icon}"> | ||
<ui:CardControl.Header> | ||
<Grid> | ||
<Grid.RowDefinitions> | ||
<RowDefinition Height="Auto" /> | ||
<RowDefinition Height="Auto" /> | ||
</Grid.RowDefinitions> | ||
<ui:TextBlock Grid.Row="0" | ||
FontTypography="Body" | ||
Text="{TemplateBinding Title}" /> | ||
<ui:TextBlock Grid.Row="1" | ||
Foreground="{ui:ThemeResource TextFillColorSecondaryBrush}" | ||
Text="{TemplateBinding Description}" /> | ||
</Grid> | ||
</ui:CardControl.Header> | ||
<Grid Margin="10,0" | ||
VerticalAlignment="Center"> | ||
<ContentControl x:Name="PART_Content" | ||
Content="{TemplateBinding Item}" /> | ||
<ui:ToggleSwitch x:Name="PART_ToggleSwitch" | ||
IsChecked="{TemplateBinding IsOn}" | ||
OffContent="Off" | ||
OnContent="On" /> | ||
</Grid> | ||
</ui:CardControl> | ||
</ControlTemplate> | ||
</Setter.Value> | ||
</Setter> | ||
</Style> | ||
</ResourceDictionary> |
105 changes: 105 additions & 0 deletions
105
VSIX/DevWinUI_Template/DevWinUI_Template/Controls/SettingsControlWithExpander.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,105 @@ | ||
using System; | ||
using System.Windows; | ||
using System.Windows.Controls; | ||
using System.Windows.Markup; | ||
using Wpf.Ui.Controls; | ||
|
||
namespace DevWinUI_Template; | ||
[TemplatePart(Name = nameof(PART_ToggleSwitch), Type = typeof(ToggleSwitch))] | ||
[ContentProperty(nameof(Item))] | ||
public class SettingsControlWithExpander : Control | ||
{ | ||
private string PART_ToggleSwitch = "PART_ToggleSwitch"; | ||
private ToggleSwitch _ToggleSwitch; | ||
|
||
public bool IsExpanded | ||
{ | ||
get { return (bool)GetValue(IsExpandedProperty); } | ||
set { SetValue(IsExpandedProperty, value); } | ||
} | ||
|
||
public static readonly DependencyProperty IsExpandedProperty = | ||
DependencyProperty.Register(nameof(IsExpanded), typeof(bool), typeof(SettingsControlWithExpander), new PropertyMetadata(false)); | ||
|
||
public string Title | ||
{ | ||
get { return (string)GetValue(TitleProperty); } | ||
set { SetValue(TitleProperty, value); } | ||
} | ||
|
||
public static readonly DependencyProperty TitleProperty = | ||
DependencyProperty.Register(nameof(Title), typeof(string), typeof(SettingsControlWithExpander), new PropertyMetadata(default(string))); | ||
|
||
public string Description | ||
{ | ||
get { return (string)GetValue(DescriptionProperty); } | ||
set { SetValue(DescriptionProperty, value); } | ||
} | ||
|
||
public static readonly DependencyProperty DescriptionProperty = | ||
DependencyProperty.Register(nameof(Description), typeof(string), typeof(SettingsControlWithExpander), new PropertyMetadata(default(string))); | ||
|
||
public bool IsOn | ||
{ | ||
get { return (bool)GetValue(IsOnProperty); } | ||
set { SetValue(IsOnProperty, value); } | ||
} | ||
|
||
public static readonly DependencyProperty IsOnProperty = | ||
DependencyProperty.Register(nameof(IsOn), typeof(bool), typeof(SettingsControlWithExpander), new PropertyMetadata(false)); | ||
|
||
public IconElement Icon | ||
{ | ||
get { return (IconElement)GetValue(IconProperty); } | ||
set { SetValue(IconProperty, value); } | ||
} | ||
|
||
public static readonly DependencyProperty IconProperty = | ||
DependencyProperty.Register(nameof(Icon), typeof(IconElement), typeof(SettingsControlWithExpander), new PropertyMetadata(null)); | ||
public string OnContent | ||
{ | ||
get { return (string)GetValue(OnContentProperty); } | ||
set { SetValue(OnContentProperty, value); } | ||
} | ||
|
||
public static readonly DependencyProperty OnContentProperty = | ||
DependencyProperty.Register(nameof(OnContent), typeof(string), typeof(SettingsControlWithExpander), new PropertyMetadata(default(string))); | ||
|
||
public string OffContent | ||
{ | ||
get { return (string)GetValue(OffContentProperty); } | ||
set { SetValue(OffContentProperty, value); } | ||
} | ||
|
||
public static readonly DependencyProperty OffContentProperty = | ||
DependencyProperty.Register(nameof(OffContent), typeof(string), typeof(SettingsControlWithExpander), new PropertyMetadata(default(string))); | ||
|
||
public FrameworkElement Item | ||
{ | ||
get { return (FrameworkElement)GetValue(ItemProperty); } | ||
set { SetValue(ItemProperty, value); } | ||
} | ||
|
||
public static readonly DependencyProperty ItemProperty = | ||
DependencyProperty.Register(nameof(Item), typeof(FrameworkElement), typeof(SettingsControlWithExpander), new PropertyMetadata(null)); | ||
|
||
public event EventHandler<RoutedEventArgs> Toggled; | ||
|
||
public override void OnApplyTemplate() | ||
{ | ||
base.OnApplyTemplate(); | ||
_ToggleSwitch = GetTemplateChild(nameof(PART_ToggleSwitch)) as ToggleSwitch; | ||
if (_ToggleSwitch != null) | ||
{ | ||
_ToggleSwitch.Checked -= OnToggleChecked; | ||
_ToggleSwitch.Unchecked -= OnToggleChecked; | ||
_ToggleSwitch.Checked += OnToggleChecked; | ||
_ToggleSwitch.Unchecked += OnToggleChecked; | ||
} | ||
} | ||
|
||
private void OnToggleChecked(object sender, RoutedEventArgs e) | ||
{ | ||
Toggled?.Invoke(this, e); | ||
} | ||
} |
Oops, something went wrong.