Skip to content

Commit

Permalink
Merge pull request #2 from ghost1372/Wizard
Browse files Browse the repository at this point in the history
Wizard
  • Loading branch information
ghost1372 authored Nov 28, 2024
2 parents 9a39b1a + 53b2b8b commit 47f7c19
Show file tree
Hide file tree
Showing 62 changed files with 1,506 additions and 1,687 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ public static class WizardConfig
public static Dictionary<string, string> CSProjectElements = new Dictionary<string, string>();
public static Dictionary<string, string> UnvirtualizedResources = new Dictionary<string, string>();

public static string DotNetVersion = "net8.0";
public static string TargetFrameworkVersion = "22621";
public static string DotNetVersion = "net9.0";
public static string TargetFrameworkVersion = "26100";
public static string MinimumTargetPlatform = "17763";
public static string Platforms = "x86;x64;ARM64";
public static string RuntimeIdentifiers = "win-x86;win-x64;win-arm64";
Expand Down
127 changes: 127 additions & 0 deletions VSIX/DevWinUI_Template/DevWinUI_Template/Controls/SettingsControl.cs
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);
}
}
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>
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);
}
}
Loading

0 comments on commit 47f7c19

Please sign in to comment.