Skip to content

Commit ab41fd5

Browse files
authored
Feature: Riverside.Toolkit.Controls.Settings (#116)
1 parent 1d0b634 commit ab41fd5

File tree

11 files changed

+498
-0
lines changed

11 files changed

+498
-0
lines changed

CubeKit.slnx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
<Project Path="src/core/Riverside.Toolkit.Animations/Riverside.Toolkit.Animations.shproj" />
3737
<Project Path="src/core/Riverside.Toolkit.Controls.Crimson/Riverside.Toolkit.Controls.Crimson.shproj" Id="f2ca66e2-ab46-45c2-88f1-a2ad68cf8c66" />
3838
<Project Path="src/core/Riverside.Toolkit.Controls.Primitives/Riverside.Toolkit.Controls.Primitives.shproj" />
39+
<Project Path="src/core/Riverside.Toolkit.Controls.Settings/Riverside.Toolkit.Controls.Settings.shproj" Id="d131c7fe-6aed-4515-8c28-17da95b09fea" />
3940
<Project Path="src/core/Riverside.Toolkit.Controls.TitleBar/Riverside.Toolkit.Controls.TitleBar.shproj" />
4041
<Project Path="src/core/Riverside.Toolkit.Converters/Riverside.Toolkit.Converters.shproj" />
4142
<Project Path="src/core/Riverside.Toolkit.Extensions/Riverside.Toolkit.Extensions.shproj" />
@@ -63,6 +64,7 @@
6364
</Project>
6465
<Project Path="src/platforms/Riverside.GlowUI.WinUI.Styles/Riverside.GlowUI.WinUI.Styles.csproj" Id="14a51f57-a0de-4539-aa52-53aad65380b5" />
6566
<Project Path="src/platforms/Riverside.Toolkit.Uno.Controls.Primitives/Riverside.Toolkit.Uno.Controls.Primitives.csproj" />
67+
<Project Path="src/platforms/Riverside.Toolkit.Uno.Controls.Settings/Riverside.Toolkit.Uno.Controls.Settings.csproj" Id="0a6ee9c5-b4ea-4b73-bc83-ce018881cc53" />
6668
<Project Path="src/platforms/Riverside.Toolkit.Uno.Converters/Riverside.Toolkit.Uno.Converters.csproj" />
6769
<Project Path="src/platforms/Riverside.Toolkit.Uno.Extensions/Riverside.Toolkit.Uno.Extensions.csproj" />
6870
<Project Path="src/platforms/Riverside.Toolkit.Uno.Helpers/Riverside.Toolkit.Uno.Helpers.csproj" />
@@ -77,6 +79,9 @@
7779
<Project Path="src/platforms/Riverside.Toolkit.Uwp.Controls.Primitives/Riverside.Toolkit.Uwp.Controls.Primitives.csproj">
7880
<Platform Solution="Release|*" Project="x64" />
7981
</Project>
82+
<Project Path="src/platforms/Riverside.Toolkit.Uwp.Controls.Settings/Riverside.Toolkit.Uwp.Controls.Settings.csproj" Id="665b6b8f-808f-42cf-b85f-6e924bfe7e3a">
83+
<Platform Solution="Release|*" Project="x64" />
84+
</Project>
8085
<Project Path="src/platforms/Riverside.Toolkit.Uwp.Converters/Riverside.Toolkit.Uwp.Converters.csproj">
8186
<Platform Solution="Release|*" Project="x64" />
8287
</Project>
@@ -98,6 +103,7 @@
98103
<Project Path="src/platforms/Riverside.Toolkit.WinUI.Animations/Riverside.Toolkit.WinUI.Animations.csproj" />
99104
<Project Path="src/platforms/Riverside.Toolkit.WinUI.Controls.Crimson/Riverside.Toolkit.WinUI.Controls.Crimson.csproj" Id="e50ac24a-5e97-4309-9197-1a3bed5f0505" />
100105
<Project Path="src/platforms/Riverside.Toolkit.WinUI.Controls.Primitives/Riverside.Toolkit.WinUI.Controls.Primitives.csproj" />
106+
<Project Path="src/platforms/Riverside.Toolkit.WinUI.Controls.Settings/Riverside.Toolkit.WinUI.Controls.Settings.csproj" Id="5536109a-3f16-4a88-a4e6-a8b6f070d877" />
101107
<Project Path="src/platforms/Riverside.Toolkit.WinUI.Controls.TitleBar/Riverside.Toolkit.WinUI.Controls.TitleBar.csproj" />
102108
<Project Path="src/platforms/Riverside.Toolkit.WinUI.Converters/Riverside.Toolkit.WinUI.Converters.csproj" />
103109
<Project Path="src/platforms/Riverside.Toolkit.WinUI.Extensions/Riverside.Toolkit.WinUI.Extensions.csproj" />

eng/MultiTarget/GlobalUsings.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
global using global::Microsoft.UI.Xaml.Media.Animation;
3333
global using global::Microsoft.UI.Xaml.Shapes;
3434
global using global::Microsoft.UI.Xaml.Controls.Primitives;
35+
global using global::Microsoft.UI.Xaml.Automation;
3536
#elif Uwp
3637
global using global::Windows;
3738
global using global::Windows.UI.Xaml;
@@ -47,6 +48,7 @@
4748
global using global::Windows.UI.Xaml.Media.Animation;
4849
global using global::Windows.UI.Xaml.Shapes;
4950
global using global::Windows.UI.Xaml.Controls.Primitives;
51+
global using global::Windows.UI.Xaml.Automation;
5052
#elif Wpf
5153
global using global::System.Windows;
5254
global using global::System.Windows.Controls;
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<MSBuildAllProjects Condition="'$(MSBuildVersion)' == '' Or '$(MSBuildVersion)' &lt; '16.0'">$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
5+
<HasSharedItems>true</HasSharedItems>
6+
<SharedGUID>d131c7fe-6aed-4515-8c28-17da95b09fea</SharedGUID>
7+
</PropertyGroup>
8+
<PropertyGroup Label="Configuration">
9+
<Import_RootNamespace>Riverside.Toolkit.Controls.Settings</Import_RootNamespace>
10+
</PropertyGroup>
11+
<ItemGroup>
12+
<Compile Include="..\..\core\$(Import_RootNamespace)\**\*.cs" Exclude="obj\**;bin\**" />
13+
<Page Include="..\..\core\$(Import_RootNamespace)\**\*.xaml" Exclude="obj\**;bin\**">
14+
<XamlRuntime>$(DefaultXamlRuntime)</XamlRuntime>
15+
<Generator>MSBuild:Compile</Generator>
16+
<SubType>Designer</SubType>
17+
</Page>
18+
</ItemGroup>
19+
</Project>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup Label="Globals">
4+
<ProjectGuid>d131c7fe-6aed-4515-8c28-17da95b09fea</ProjectGuid>
5+
<MinimumVisualStudioVersion>14.0</MinimumVisualStudioVersion>
6+
</PropertyGroup>
7+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
8+
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.Common.Default.props" />
9+
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.Common.props" />
10+
<PropertyGroup />
11+
<Import Project="Riverside.Toolkit.Controls.Settings.projitems" Label="Shared" />
12+
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.CSharp.targets" />
13+
</Project>
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
<UserControl
2+
x:Class="Riverside.Toolkit.Controls.SettingsBlockControl"
3+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
4+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
5+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
6+
xmlns:local="using:Riverside.Toolkit.Controls"
7+
xmlns:local1="using:Riverside.Toolkit.Converters"
8+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
9+
xmlns:muxc="using:Microsoft.UI.Xaml.Controls"
10+
d:DesignHeight="300"
11+
d:DesignWidth="400"
12+
mc:Ignorable="d">
13+
14+
<UserControl.Resources>
15+
<local1:InverseBooleanConverter x:Key="InverseBooleanConverter" />
16+
<local1:NullToTrueConverter x:Key="NullToFalseConverter" Inverse="True" />
17+
<local1:NullToTrueConverter x:Key="NullToTrueConverter" Inverse="False" />
18+
<local1:StringNullOrWhiteSpaceToTrueConverter x:Key="StringNullOrWhiteSpaceToFalseConverter" Inverse="True" />
19+
<local1:StringNullOrWhiteSpaceToTrueConverter x:Key="StringNullOrWhiteSpaceToTrueConverter" Inverse="False" />
20+
21+
<Style x:Key="TextBlockGroupHeaderStyle" TargetType="TextBlock">
22+
<Setter Property="Margin" Value="0,8,0,4" />
23+
<Setter Property="FontSize" Value="16" />
24+
<Setter Property="TextWrapping" Value="Wrap" />
25+
<Setter Property="FontWeight" Value="Bold" />
26+
</Style>
27+
28+
<Style x:Key="GridSettingsBlockStyle" TargetType="Grid">
29+
<Setter Property="Background" Value="{ThemeResource ExpanderHeaderBackground}" />
30+
<Setter Property="BorderBrush" Value="{ThemeResource ExpanderHeaderBorderBrush}" />
31+
<Setter Property="BorderThickness" Value="{ThemeResource ExpanderHeaderBorderThickness}" />
32+
<Setter Property="HorizontalAlignment" Value="Stretch" />
33+
<Setter Property="MinHeight" Value="{StaticResource ExpanderMinHeight}" />
34+
<Setter Property="Padding" Value="16,4,16,4" />
35+
<Setter Property="CornerRadius" Value="{ThemeResource ControlCornerRadius}" />
36+
</Style>
37+
38+
<Style
39+
x:Key="ButtonSettingsBlockStyle"
40+
BasedOn="{StaticResource DefaultButtonStyle}"
41+
TargetType="Button">
42+
<Setter Property="Background" Value="{ThemeResource ExpanderHeaderBackground}" />
43+
<Setter Property="BorderBrush" Value="{ThemeResource ExpanderHeaderBorderBrush}" />
44+
<Setter Property="BorderThickness" Value="{ThemeResource ExpanderHeaderBorderThickness}" />
45+
<Setter Property="HorizontalAlignment" Value="Stretch" />
46+
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
47+
<Setter Property="Padding" Value="16,4,16,4" />
48+
<Setter Property="MinHeight" Value="{StaticResource ExpanderMinHeight}" />
49+
<Setter Property="CornerRadius" Value="{ThemeResource ControlCornerRadius}" />
50+
</Style>
51+
</UserControl.Resources>
52+
53+
<Grid>
54+
55+
<!-- Expander -->
56+
<Grid x:Name="ExpanderPreGrid" x:Load="{x:Bind ExpandableContent, Mode=OneWay, Converter={StaticResource NullToFalseConverter}}">
57+
<Grid x:Name="ExpanderGrid" x:Load="{x:Bind IsClickable, Mode=OneWay, Converter={StaticResource InverseBooleanConverter}}">
58+
<muxc:Expander
59+
x:Name="ExpanderControl"
60+
HorizontalAlignment="Stretch"
61+
HorizontalContentAlignment="Stretch"
62+
AutomationProperties.Name="{x:Bind Title, Mode=OneWay}"
63+
Collapsed="Expander_Collapsed"
64+
Expanding="Expander_Expanding"
65+
IsExpanded="{x:Bind IsExpanded, Mode=TwoWay}">
66+
<muxc:Expander.Header>
67+
<local:SettingsDisplayControl
68+
Title="{x:Bind Title, Mode=OneWay}"
69+
Margin="0,4"
70+
AdditionalDescriptionContent="{x:Bind AdditionalDescriptionContent, Mode=OneWay}"
71+
Description="{x:Bind Description, Mode=OneWay}"
72+
Icon="{x:Bind Icon, Mode=OneWay}"
73+
SettingsActionableElement="{x:Bind SettingsActionableElement, Mode=OneWay}" />
74+
</muxc:Expander.Header>
75+
76+
<ContentPresenter
77+
Margin="-16"
78+
HorizontalAlignment="Stretch"
79+
Content="{x:Bind ExpandableContent, Mode=OneWay}" />
80+
</muxc:Expander>
81+
</Grid>
82+
</Grid>
83+
84+
<!-- Button -->
85+
<Grid x:Name="ButtonPreGrid" x:Load="{x:Bind ExpandableContent, Mode=OneWay, Converter={StaticResource NullToTrueConverter}}">
86+
<Grid x:Name="ButtonGrid" x:Load="{x:Bind IsClickable, Mode=OneWay}">
87+
<Button
88+
x:Name="ActionableButton"
89+
Command="{x:Bind ButtonCommand, Mode=OneWay}"
90+
Style="{StaticResource ButtonSettingsBlockStyle}">
91+
<local:SettingsDisplayControl
92+
Title="{x:Bind Title, Mode=OneWay}"
93+
AdditionalDescriptionContent="{x:Bind AdditionalDescriptionContent, Mode=OneWay}"
94+
Description="{x:Bind Description, Mode=OneWay}"
95+
Icon="{x:Bind Icon, Mode=OneWay}"
96+
SettingsActionableElement="{x:Bind SettingsActionableElement, Mode=OneWay}" />
97+
</Button>
98+
</Grid>
99+
</Grid>
100+
101+
<!-- Grid -->
102+
<Grid x:Name="StaticPreGrid" x:Load="{x:Bind ExpandableContent, Mode=OneWay, Converter={StaticResource NullToTrueConverter}}">
103+
<Grid
104+
x:Name="StaticGrid"
105+
x:Load="{x:Bind IsClickable, Mode=OneWay, Converter={StaticResource InverseBooleanConverter}}"
106+
Style="{StaticResource GridSettingsBlockStyle}">
107+
<local:SettingsDisplayControl
108+
Title="{x:Bind Title, Mode=OneWay}"
109+
AdditionalDescriptionContent="{x:Bind AdditionalDescriptionContent, Mode=OneWay}"
110+
Description="{x:Bind Description, Mode=OneWay}"
111+
Icon="{x:Bind Icon, Mode=OneWay}"
112+
SettingsActionableElement="{x:Bind SettingsActionableElement, Mode=OneWay}" />
113+
</Grid>
114+
</Grid>
115+
116+
</Grid>
117+
</UserControl>
Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
using System;
2+
using System.Windows.Input;
3+
4+
namespace Riverside.Toolkit.Controls
5+
{
6+
[ContentProperty(Name = nameof(SettingsActionableElement))]
7+
public sealed partial class SettingsBlockControl : UserControl
8+
{
9+
public FrameworkElement SettingsActionableElement { get; set; }
10+
11+
public ICommand ButtonCommand
12+
{
13+
get { return (ICommand)GetValue(ButtonCommandProperty); }
14+
set { SetValue(ButtonCommandProperty, value); }
15+
}
16+
public static readonly DependencyProperty ButtonCommandProperty =
17+
DependencyProperty.Register("ButtonCommand", typeof(ICommand), typeof(SettingsBlockControl), new PropertyMetadata(null));
18+
19+
public static readonly DependencyProperty ExpandableContentProperty = DependencyProperty.Register(
20+
"ExpandableContent",
21+
typeof(FrameworkElement),
22+
typeof(SettingsBlockControl),
23+
new PropertyMetadata(null)
24+
);
25+
26+
public FrameworkElement ExpandableContent
27+
{
28+
get => (FrameworkElement)GetValue(ExpandableContentProperty);
29+
set => SetValue(ExpandableContentProperty, value);
30+
}
31+
32+
public static readonly DependencyProperty AdditionalDescriptionContentProperty = DependencyProperty.Register(
33+
"AdditionalDescriptionContent",
34+
typeof(FrameworkElement),
35+
typeof(SettingsBlockControl),
36+
new PropertyMetadata(null)
37+
);
38+
39+
public FrameworkElement AdditionalDescriptionContent
40+
{
41+
get => (FrameworkElement)GetValue(AdditionalDescriptionContentProperty);
42+
set => SetValue(AdditionalDescriptionContentProperty, value);
43+
}
44+
45+
public static readonly DependencyProperty TitleProperty = DependencyProperty.Register(
46+
"Title",
47+
typeof(string),
48+
typeof(SettingsBlockControl),
49+
new PropertyMetadata(null)
50+
);
51+
52+
public string Title
53+
{
54+
get => (string)GetValue(TitleProperty);
55+
set => SetValue(TitleProperty, value);
56+
}
57+
58+
public static readonly DependencyProperty DescriptionProperty = DependencyProperty.Register(
59+
"Description",
60+
typeof(string),
61+
typeof(SettingsBlockControl),
62+
new PropertyMetadata(null)
63+
);
64+
65+
public string Description
66+
{
67+
get => (string)GetValue(DescriptionProperty);
68+
set => SetValue(DescriptionProperty, value);
69+
}
70+
71+
public static readonly DependencyProperty IconProperty = DependencyProperty.Register(
72+
"Icon",
73+
typeof(IconElement),
74+
typeof(SettingsBlockControl),
75+
new PropertyMetadata(null)
76+
);
77+
78+
public IconElement Icon
79+
{
80+
get => (IconElement)GetValue(IconProperty);
81+
set => SetValue(IconProperty, value);
82+
}
83+
84+
public static readonly DependencyProperty IsClickableProperty = DependencyProperty.Register(
85+
"IsClickable",
86+
typeof(bool),
87+
typeof(SettingsBlockControl),
88+
new PropertyMetadata(false)
89+
);
90+
91+
public bool IsClickable
92+
{
93+
get => (bool)GetValue(IsClickableProperty);
94+
set => SetValue(IsClickableProperty, value);
95+
}
96+
97+
public static readonly DependencyProperty IsExpandedProperty = DependencyProperty.Register(
98+
"IsExpanded",
99+
typeof(bool),
100+
typeof(SettingsBlockControl),
101+
new PropertyMetadata(false)
102+
);
103+
104+
public bool IsExpanded
105+
{
106+
get => (bool)GetValue(IsExpandedProperty);
107+
set => SetValue(IsExpandedProperty, value);
108+
}
109+
110+
//
111+
// Summary:
112+
// Occurs when a button control is clicked.
113+
public event EventHandler<bool> Click;
114+
115+
public SettingsBlockControl()
116+
{
117+
InitializeComponent();
118+
Loaded += SettingsBlockControl_Loaded;
119+
}
120+
121+
private void SettingsBlockControl_Loaded(object sender, RoutedEventArgs e)
122+
{
123+
if (ActionableButton is not null)
124+
{
125+
AutomationProperties.SetName(ActionableButton, Title);
126+
}
127+
}
128+
129+
private void Expander_Expanding(Microsoft.UI.Xaml.Controls.Expander sender, Microsoft.UI.Xaml.Controls.ExpanderExpandingEventArgs args)
130+
{
131+
Click?.Invoke(this, true);
132+
}
133+
134+
private void Expander_Collapsed(Microsoft.UI.Xaml.Controls.Expander sender, Microsoft.UI.Xaml.Controls.ExpanderCollapsedEventArgs args)
135+
{
136+
Click?.Invoke(this, false);
137+
}
138+
}
139+
}

0 commit comments

Comments
 (0)