Skip to content
Merged
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 @@ -74,6 +74,7 @@ public override string ToString()
new GalleryPageFactory(() => new SearchBarCoreGalleryPage(), "Search Bar Gallery"),
new GalleryPageFactory(() => new SliderCoreGalleryPage(), "Slider Gallery"),
new GalleryPageFactory(() => new StepperCoreGalleryPage(), "Stepper Gallery"),
new GalleryPageFactory(() => new SwitchControlPage(), "Switch Feature Matrix"),
new GalleryPageFactory(() => new SwitchCoreGalleryPage(), "Switch Gallery"),
new GalleryPageFactory(() => new SwipeViewCoreGalleryPage(), "SwipeView Gallery"),
new GalleryPageFactory(() => new TimePickerCoreGalleryPage(), "Time Picker Gallery"),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:Maui.Controls.Sample"
x:Class="Maui.Controls.Sample.SwitchControlMainPage"
x:DataType="local:SwitchViewModel"
Title="SwitchControlPage">
<ContentPage.ToolbarItems>
<ToolbarItem Text="Options"
Clicked="NavigateToOptionsPage_Clicked"
AutomationId="Options"/>
</ContentPage.ToolbarItems>

<Grid RowDefinitions="*,Auto">
<Grid x:Name="SwitchGrid"
Grid.Row="0">
<Switch AutomationId="SwitchControl"
FlowDirection="{Binding FlowDirection}"
IsEnabled="{Binding IsEnabled}"
IsVisible="{Binding IsVisible}"
IsToggled="{Binding IsToggled}"
OnColor="{Binding OnColor}"
Shadow="{Binding Shadow}"
ThumbColor="{Binding ThumbColor}"
HorizontalOptions="Center"
VerticalOptions="Center"
Toggled="Switch_Toggled">
</Switch>
</Grid>
<HorizontalStackLayout Grid.Row="1"
HorizontalOptions="Center"
Padding="0,0,0,40"
Spacing="10">
<Label Text="Toggled Event: "/>
<Label x:Name="EventLabel"
AutomationId="ToggledEventLabel"
Text="False"/>
</HorizontalStackLayout>
</Grid>
</ContentPage>
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
namespace Maui.Controls.Sample;

public class SwitchControlPage : NavigationPage
{
private SwitchViewModel _viewModel;
public SwitchControlPage()
{
_viewModel = new SwitchViewModel();
PushAsync(new SwitchControlMainPage(_viewModel));
}
}

public partial class SwitchControlMainPage : ContentPage
{
private SwitchViewModel _viewModel;

public SwitchControlMainPage(SwitchViewModel viewModel)
{
InitializeComponent();
_viewModel = viewModel;
BindingContext = _viewModel;
}

private async void NavigateToOptionsPage_Clicked(object sender, EventArgs e)
{
BindingContext = _viewModel = new SwitchViewModel();
ReinitializeSwitch();
await Navigation.PushAsync(new SwitchOptionsPage(_viewModel));
}

private void Switch_Toggled(object sender, ToggledEventArgs e)
{
EventLabel.Text = $"{e.Value}";
}

private void ReinitializeSwitch()
{
SwitchGrid.Children.Clear();
var switchControl = new Switch
{
AutomationId = "SwitchControl",
HorizontalOptions = LayoutOptions.Center,
VerticalOptions = LayoutOptions.Center
};

switchControl.Toggled += Switch_Toggled;

switchControl.SetBinding(Switch.FlowDirectionProperty, new Binding(nameof(SwitchViewModel.FlowDirection)));
switchControl.SetBinding(Switch.IsEnabledProperty, new Binding(nameof(SwitchViewModel.IsEnabled)));
switchControl.SetBinding(Switch.IsVisibleProperty, new Binding(nameof(SwitchViewModel.IsVisible)));
switchControl.SetBinding(Switch.IsToggledProperty, new Binding(nameof(SwitchViewModel.IsToggled)));
switchControl.SetBinding(Switch.OnColorProperty, new Binding(nameof(SwitchViewModel.OnColor)));
switchControl.SetBinding(Switch.ShadowProperty, new Binding(nameof(SwitchViewModel.Shadow)));
switchControl.SetBinding(Switch.ThumbColorProperty, new Binding(nameof(SwitchViewModel.ThumbColor)));
SwitchGrid.Children.Add(switchControl);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:Maui.Controls.Sample"
x:Class="Maui.Controls.Sample.SwitchOptionsPage"
x:DataType="local:SwitchViewModel"
Title="SwitchOptionsPage">
<ContentPage.ToolbarItems>
<ToolbarItem Text="Apply"
Clicked="ApplyButton_Clicked"
AutomationId="Apply"/>
</ContentPage.ToolbarItems>

<Grid ColumnSpacing="10"
RowSpacing="10"
RowDefinitions="Auto,Auto,Auto,Auto,Auto,Auto,Auto"
ColumnDefinitions="Auto,Auto"
HorizontalOptions="Center"
VerticalOptions="Center">

<!-- FlowDirection -->
<Label Grid.Row="0"
Grid.Column="0"
Text="FlowDirection:"
VerticalOptions="Center"/>
<StackLayout Grid.Row="0"
Grid.Column="1"
Orientation="Horizontal"
Spacing="5"
VerticalOptions="Center">
<CheckBox x:Name="FlowDirectionLeftToRightCheckBox"
AutomationId="FlowDirectionLeftToRightCheckBox"
IsChecked="True"
CheckedChanged="OnFlowDirectionCheckBoxCheckedChanged"/>
<Label Text="LeftToRight"
VerticalOptions="Center"/>
<CheckBox x:Name="FlowDirectionRightToLeftCheckBox"
AutomationId="FlowDirectionRightToLeftCheckBox"
CheckedChanged="OnFlowDirectionCheckBoxCheckedChanged"/>
<Label Text="RightToLeft"
VerticalOptions="Center"/>
</StackLayout>

<!-- IsEnabled -->
<Label Grid.Row="1"
Grid.Column="0"
Text="IsEnabled:"
VerticalOptions="Center"/>
<StackLayout Grid.Row="1"
Grid.Column="1"
Orientation="Horizontal"
Spacing="10"
VerticalOptions="Center">
<CheckBox AutomationId="IsEnabledFalseCheckBox"
CheckedChanged="OnEnabledCheckBoxCheckedChanged"/>
</StackLayout>

<!-- IsVisible -->
<Label Grid.Row="2"
Grid.Column="0"
Text="IsVisible:"
VerticalOptions="Center"/>
<StackLayout Grid.Row="2"
Grid.Column="1"
Orientation="Horizontal"
Spacing="10"
VerticalOptions="Center">
<CheckBox AutomationId="IsVisibleFalseCheckBox"
CheckedChanged="OnVisibleCheckBoxCheckedChanged"/>
</StackLayout>

<!-- IsToggled -->
<Label Grid.Row="3"
Grid.Column="0"
Text="IsToggled:"
VerticalOptions="Center"/>
<StackLayout Grid.Row="3"
Grid.Column="1"
Orientation="Horizontal"
Spacing="10"
VerticalOptions="Center">
<CheckBox AutomationId="IsToggledTrueCheckBox"
CheckedChanged="OnToggledCheckBoxCheckedChanged"/>
</StackLayout>

<!-- OnColor -->
<Label Grid.Row="4"
Grid.Column="0"
Text="OnColor:"
VerticalOptions="Center"/>
<StackLayout Grid.Row="4"
Grid.Column="1"
Orientation="Horizontal"
Spacing="5"
VerticalOptions="Center">
<CheckBox x:Name="OnColorRedCheckBox"
AutomationId="OnColorRedCheckBox"
CheckedChanged="OnOnColorCheckBoxCheckedChanged"/>
<Label Text="Red"
VerticalOptions="Center"/>
<CheckBox x:Name="OnColorGreenCheckBox"
AutomationId="OnColorGreenCheckBox"
CheckedChanged="OnOnColorCheckBoxCheckedChanged"/>
<Label Text="Green"
VerticalOptions="Center"/>
</StackLayout>

<!-- Shadow -->
<Label Grid.Row="5"
Grid.Column="0"
Text="Shadow:"
VerticalOptions="Center"/>
<HorizontalStackLayout Grid.Row="5"
Grid.Column="1"
VerticalOptions="Center">
<CheckBox AutomationId="ShadowTrueCheckBox"
CheckedChanged="OnShadowCheckBoxCheckedChanged"/>
</HorizontalStackLayout>

<!-- ThumbColor -->
<Label Grid.Row="6"
Grid.Column="0"
Text="ThumbColor:"
VerticalOptions="Center"/>
<StackLayout Grid.Row="6"
Grid.Column="1"
Orientation="Horizontal"
Spacing="5"
VerticalOptions="Center">
<CheckBox x:Name="ThumbColorRedCheckBox"
AutomationId="ThumbColorRedCheckBox"
CheckedChanged="OnThumbColorCheckBoxCheckedChanged"/>
<Label Text="Red"
VerticalOptions="Center"/>
<CheckBox x:Name="ThumbColorGreenCheckBox"
AutomationId="ThumbColorGreenCheckBox"
CheckedChanged="OnThumbColorCheckBoxCheckedChanged"/>
<Label Text="Green"
VerticalOptions="Center"/>
</StackLayout>
</Grid>
</ContentPage>
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
using Maui.Controls.Sample;

namespace Maui.Controls.Sample;

public partial class SwitchOptionsPage : ContentPage
{
private SwitchViewModel _viewModel;
public SwitchOptionsPage(SwitchViewModel viewModel)
{
InitializeComponent();
_viewModel = viewModel;
BindingContext = _viewModel;
}
private void ApplyButton_Clicked(object sender, EventArgs e)
{
Navigation.PopAsync();
}

private void OnFlowDirectionCheckBoxCheckedChanged(object sender, CheckedChangedEventArgs e)
{
if (!(sender is CheckBox changedBox) || !changedBox.IsChecked)
return;
if (changedBox == FlowDirectionLeftToRightCheckBox)
{
FlowDirectionRightToLeftCheckBox.IsChecked = false;
_viewModel.FlowDirection = FlowDirection.LeftToRight;
}
else if (changedBox == FlowDirectionRightToLeftCheckBox)
{
FlowDirectionLeftToRightCheckBox.IsChecked = false;
_viewModel.FlowDirection = FlowDirection.RightToLeft;
}
}

private void OnEnabledCheckBoxCheckedChanged(object sender, CheckedChangedEventArgs e)
{
if (e.Value)
{
_viewModel.IsEnabled = false;
}
else
{
_viewModel.IsEnabled = true;
}
}

private void OnVisibleCheckBoxCheckedChanged(object sender, CheckedChangedEventArgs e)
{

if (e.Value)
{
_viewModel.IsVisible = false;
}
else
{
_viewModel.IsVisible = true;
}
}

private void OnToggledCheckBoxCheckedChanged(object sender, CheckedChangedEventArgs e)
{
if (e.Value)
{
_viewModel.IsToggled = true;
}
else
{
_viewModel.IsToggled = false;
}
}

private void OnOnColorCheckBoxCheckedChanged(object sender, CheckedChangedEventArgs e)
{
if (!(sender is CheckBox changedBox) || !changedBox.IsChecked)
return;
if (changedBox == OnColorRedCheckBox)
{
OnColorGreenCheckBox.IsChecked = false;
_viewModel.OnColor = Colors.Red;
}
else if (changedBox == OnColorGreenCheckBox)
{
OnColorRedCheckBox.IsChecked = false;
_viewModel.OnColor = Colors.Green;
}
}

private void OnShadowCheckBoxCheckedChanged(object sender, CheckedChangedEventArgs e)
{
if (e.Value)
{
_viewModel.Shadow = new Shadow { Brush = Colors.Violet, Radius = 20, Offset = new Point(0, 0), Opacity = 1f };
}
else
{
_viewModel.Shadow = null;
}
}

private void OnThumbColorCheckBoxCheckedChanged(object sender, CheckedChangedEventArgs e)
{
if (!(sender is CheckBox changedBox) || !changedBox.IsChecked)
return;
if (changedBox == ThumbColorRedCheckBox)
{
ThumbColorGreenCheckBox.IsChecked = false;
_viewModel.ThumbColor = Colors.Red;
}
else if (changedBox == ThumbColorGreenCheckBox)
{
ThumbColorRedCheckBox.IsChecked = false;
_viewModel.ThumbColor = Colors.Green;
}
}
}
Loading
Loading