Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions components/SettingsControls/samples/SettingsCard.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,9 @@ You can set the `Header`, `Description`, `HeaderIcon` and `Content` properties t
SettingsCard can also be turned into a button, by setting the `IsClickEnabled` property. This can be useful whenever you want your settings component to navigate to a detail page or open an external link. You can set a custom icon by setting the `ActionIcon`, or hiding it completely by setting the `IsActionIconVisible` to `false`.

> [!SAMPLE ClickableSettingsCardSample]

### Settings page example

The following sample provides a typical design page, following the correct Windows 11 design specifications for things like spacing, section headers and animations.

> [!SAMPLE SettingsPageExample]
20 changes: 20 additions & 0 deletions components/SettingsControls/samples/SettingsExpander.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,26 @@ You can easily override certain properties to create custom experiences. For ins

NOTE: Due to [a bug](https://github.com/microsoft/microsoft-ui-xaml/issues/3842) related to the `ItemsRepeater` used in `SettingsExpander`, there might be visual glitches whenever the `SettingsExpander` expands and a `MaxWidth` is set on a parent `StackPanel`. As a workaround, the `StackPanel` (that has the `MaxWidth` set) can be wrapped in a `Grid` to overcome this issue. See the `SettingsPageExample` for snippet.

### Dragging Settings Cards

You may use a list of `SettingsCard` or `SettingsExpander` to represent configurable items within a tool. The order of these may be something you want to track.

In this case there is a conflict between the interactions with the settings card and the drag and drop interactions of a parent containing `ListView`, for instance.

Therefore, it is recommended to use the drag-handle type UI approach for this scenario in having a dedicated space for re-ordering manipulation vs. interaction with the Settings control.

You can see how to do this with `SettingsExpander` in the example below, however it equally works with a collection of `SettingsCard` as the main data template component as well.

> [!SAMPLE SettingsExpanderDragHandleSample]

The main important pieces of this example are:

1. Enabling the three drag properties on the `ListView`: `CanDragItems`, `CanReorderItems`, and `AllowDrop`.
2. Setting `SelectionMode` to `None` to prevent selection and the selection indicator from appearing.
3. Using a simple UIElement to act as a drag handle, the pass-through of the mouse on this element to `ListView` allows the normal drag experience to work uninterrupted.
4. Modifying the `Margin` and `Padding` values of the `ItemContainerStyle` to align cards how we want within the ListView.
5. Overriding the `ListViewItemBackgroundPointerOver` resource to prevent the hover effect across the entire list item, the Settings Controls already have an effect here on hover.

### Settings page example

The following sample provides a typical design page, following the correct Windows 11 design specifications for things like spacing, section headers and animations.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<Page x:Class="SettingsControlsExperiment.Samples.SettingsExpanderDragHandleSample"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="using:CommunityToolkit.WinUI.Controls"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="using:SettingsControlsExperiment.Samples"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">

<!--
Enabled the List view to drag its items and reorder them around,
plus need SelectionMode None so the indicator doesn't appear when clicking on the drag region
-->
<ListView AllowDrop="True"
CanDragItems="True"
CanReorderItems="True"
ItemsSource="{x:Bind MyDataSet}"
SelectionMode="None">
<ListView.ItemTemplate>
<DataTemplate x:DataType="local:ExpandedCardInfo">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<!-- Provide a custom area that can be manipulated by the user -->
<!-- TODO: Show how to highlight this on hover with a behavior -->
<Border Width="18"
Margin="1,1,0,1"
Padding="0"
VerticalAlignment="Stretch"
Background="{ThemeResource CardBackgroundFillColorDefaultBrush}"
CornerRadius="{ThemeResource ControlCornerRadius}">
<TextBlock HorizontalAlignment="Center"
VerticalAlignment="Center"
FontFamily="Segoe UI Symbol"
FontSize="16"
Foreground="{ThemeResource TextFillColorSecondaryBrush}"
Opacity="0.5"
Text="&#x283F;" />
</Border>
<controls:SettingsExpander Grid.Column="1"
Description="{x:Bind Info}"
Header="{x:Bind Name}">

<ToggleSwitch OffContent="Off"
OnContent="On" />

<controls:SettingsExpander.Items>
<controls:SettingsCard Header="{x:Bind LinkDescription}">
<HyperlinkButton Content="{x:Bind Url}"
NavigateUri="{x:Bind Url}" />
</controls:SettingsCard>
</controls:SettingsExpander.Items>
</controls:SettingsExpander>
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
<ListView.ItemContainerStyle>
<Style BasedOn="{StaticResource DefaultListViewItemStyle}"
TargetType="ListViewItem">
<Setter Property="Margin" Value="0" />
<Setter Property="Padding" Value="4" />
</Style>
</ListView.ItemContainerStyle>
<!-- Hides the overall highlight from the ListView Container -->
<ListView.Resources>
<SolidColorBrush x:Key="ListViewItemBackgroundPointerOver"
Color="Transparent" />
</ListView.Resources>
</ListView>
</Page>
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

namespace SettingsControlsExperiment.Samples;

[ToolkitSample(id: nameof(SettingsExpanderDragHandleSample), "SettingsExpanderDragHandle", description: "The SettingsCard/SettingsExpander can be within a collection itself which can be re-ordered.")]
public sealed partial class SettingsExpanderDragHandleSample : Page
{

public ObservableCollection<ExpandedCardInfo> MyDataSet = new() {
new()
{
Name = "First Item",
Info = "More about first item.",
LinkDescription = "Click the link for more on first item.",
Url = "https://microsoft.com/",
},
new()
{
Name = "Second Item",
Info = "More about second item.",
LinkDescription = "Click the link for more on second item.",
Url = "https://xbox.com/",
},
new()
{
Name = "Third Item",
Info = "More about third item.",
LinkDescription = "Click the link for more on third item.",
Url = "https://toolkitlabs.dev/",
},
};

public SettingsExpanderDragHandleSample()
{
this.InitializeComponent();
}
}

public class ExpandedCardInfo
{
public string? Name { get; set; }

public string? Info { get; set; }

public string? LinkDescription { get; set; }

public string? Url { get; set; }
}

58 changes: 29 additions & 29 deletions components/SettingsControls/samples/SettingsExpanderSample.xaml
Original file line number Diff line number Diff line change
@@ -1,43 +1,43 @@
<!-- Licensed to the .NET Foundation under one or more agreements. The .NET Foundation licenses this file to you under the MIT license. See the LICENSE file in the project root for more information. -->
<!-- Licensed to the .NET Foundation under one or more agreements. The .NET Foundation licenses this file to you under the MIT license. See the LICENSE file in the project root for more information. -->
<Page x:Class="SettingsControlsExperiment.Samples.SettingsExpanderSample"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="using:CommunityToolkit.WinUI.Controls"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="using:CommunityToolkit.WinUI.Controls"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:ui="using:CommunityToolkit.WinUI"
mc:Ignorable="d">

<local:SettingsExpander x:Name="settingsCard"
VerticalAlignment="Top"
Description="The SettingsExpander has the same properties as a Card, and you can set SettingsCard as part of the Items collection."
Header="SettingsExpander"
HeaderIcon="{ui:FontIcon Glyph=&#xE91B;}"
IsEnabled="{x:Bind IsCardEnabled, Mode=OneWay}"
IsExpanded="{x:Bind IsCardExpanded, Mode=OneWay}">
<controls:SettingsExpander x:Name="settingsCard"
VerticalAlignment="Top"
Description="The SettingsExpander has the same properties as a Card, and you can set SettingsCard as part of the Items collection."
Header="SettingsExpander"
HeaderIcon="{ui:FontIcon Glyph=&#xE91B;}"
IsEnabled="{x:Bind IsCardEnabled, Mode=OneWay}"
IsExpanded="{x:Bind IsCardExpanded, Mode=OneWay}">
<!-- TODO: This should be TwoWay bound but throws compile error in Uno. -->
<ComboBox SelectedIndex="0">
<ComboBoxItem>Option 1</ComboBoxItem>
<ComboBoxItem>Option 2</ComboBoxItem>
<ComboBoxItem>Option 3</ComboBoxItem>
</ComboBox>

<local:SettingsExpander.Items>
<local:SettingsCard Header="A basic SettingsCard within an SettingsExpander">
<controls:SettingsExpander.Items>
<controls:SettingsCard Header="A basic SettingsCard within an SettingsExpander">
<Button Content="Button" />
</local:SettingsCard>
<local:SettingsCard Description="SettingsCard within an Expander can be made clickable too!"
Header="This item can be clicked"
IsClickEnabled="True" />
</controls:SettingsCard>
<controls:SettingsCard Description="SettingsCard within an Expander can be made clickable too!"
Header="This item can be clicked"
IsClickEnabled="True" />

<local:SettingsCard ContentAlignment="Left">
<controls:SettingsCard ContentAlignment="Left">
<CheckBox Content="Here the ContentAlignment is set to Left. This is great for e.g. CheckBoxes or RadioButtons." />
</local:SettingsCard>
</controls:SettingsCard>

<local:SettingsCard HorizontalContentAlignment="Left"
ContentAlignment="Vertical"
Description="You can also align your content vertically. Make sure to set the HorizontalAlignment to Left when you do!"
Header="Vertically aligned">
<controls:SettingsCard HorizontalContentAlignment="Left"
ContentAlignment="Vertical"
Description="You can also align your content vertically. Make sure to set the HorizontalAlignment to Left when you do!"
Header="Vertically aligned">
<GridView SelectedIndex="1">
<GridViewItem>
<Border Width="64"
Expand All @@ -64,13 +64,13 @@
CornerRadius="4" />
</GridViewItem>
</GridView>
</local:SettingsCard>
<local:SettingsCard Description="You can override the Left indention of a SettingsCard by overriding the SettingsCardLeftIndention"
Header="Customization">
<local:SettingsCard.Resources>
</controls:SettingsCard>
<controls:SettingsCard Description="You can override the Left indention of a SettingsCard by overriding the SettingsCardLeftIndention"
Header="Customization">
<controls:SettingsCard.Resources>
<x:Double x:Key="SettingsCardLeftIndention">40</x:Double>
</local:SettingsCard.Resources>
</local:SettingsCard>
</local:SettingsExpander.Items>
</local:SettingsExpander>
</controls:SettingsCard.Resources>
</controls:SettingsCard>
</controls:SettingsExpander.Items>
</controls:SettingsExpander>
</Page>
Loading