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.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,56 +1,27 @@
using System;
using System.Windows.Input;
using Microsoft.Maui.Controls;

namespace Maui.Controls.Sample;

public partial class CheckBoxControlPage : ContentPage
{
private CheckBoxFeatureMatrixViewModel _viewModel;
private CheckBoxViewModel _viewModel;

public CheckBoxControlPage()
{
InitializeComponent();
_viewModel = new CheckBoxFeatureMatrixViewModel();
_viewModel.SetColorCommand = new Command<string>(OnSetColor);
_viewModel = new CheckBoxViewModel();
BindingContext = _viewModel;
}

private void OnSetColor(string colorName)
private void ResetButton_Clicked(object sender, EventArgs e)
{
switch (colorName)
{
case "Blue":
_viewModel.Color = Colors.Blue;
break;
case "Green":
_viewModel.Color = Colors.Green;
break;
case "Default":
default:
_viewModel.Color = null;
break;
}
}

private void NavigateToOptionsPage_Clicked(object sender, EventArgs e)
{
_viewModel = new CheckBoxFeatureMatrixViewModel();
_viewModel.SetColorCommand = new Command<string>(OnSetColor);
BindingContext = _viewModel;
_viewModel.Reset();
}

private void OnCheckBoxCheckedChanged(object sender, CheckedChangedEventArgs e)
{
_viewModel.CheckedChangedCommand.Execute(null);
}

}


// Extension of the CheckBoxFeatureMatrixViewModel to add commands for the options page
public partial class CheckBoxFeatureMatrixViewModel
{
public ICommand SetColorCommand { get; set; }
}

Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@

namespace Maui.Controls.Sample;

public partial class CheckBoxFeatureMatrixViewModel : INotifyPropertyChanged
public class CheckBoxViewModel : INotifyPropertyChanged
{
private bool _isChecked = true;
private Color _color = null;
private bool _isEnabled = true;
private bool _isVisible = true;
private bool _hasShadow = false;
private Shadow _shadow = null;
private string _checkedChangedStatus = string.Empty;
private bool _isEventStatusLabelVisible = false;
private string _commandStatus = string.Empty;
Expand All @@ -20,10 +22,11 @@ public partial class CheckBoxFeatureMatrixViewModel : INotifyPropertyChanged

public event PropertyChangedEventHandler PropertyChanged;

public CheckBoxFeatureMatrixViewModel()
public CheckBoxViewModel()
{
CheckedChangedCommand = new Command(OnCheckedChanged);
CheckBoxCommand = new Command<string>(OnCheckBoxCommand);
SetColorCommand = new Command<string>(OnSetColor);
}

public bool IsChecked
Expand Down Expand Up @@ -85,11 +88,8 @@ public string CheckedChangedStatus
{
if (_checkedChangedStatus != value)
{
if (!string.IsNullOrEmpty(value))
{
IsEventStatusLabelVisible = true;
}
_checkedChangedStatus = value;
IsEventStatusLabelVisible = !string.IsNullOrEmpty(value);
OnPropertyChanged();
}
}
Expand All @@ -110,6 +110,7 @@ public bool IsEventStatusLabelVisible

public ICommand CheckedChangedCommand { get; }
public ICommand CheckBoxCommand { get; }
public ICommand SetColorCommand { get; }

public string CommandParameter
{
Expand All @@ -131,11 +132,8 @@ public string CommandStatus
{
if (_commandStatus != value)
{
if (!string.IsNullOrEmpty(value))
{
IsCommandStatusLabelVisible = true;
}
_commandStatus = value;
IsCommandStatusLabelVisible = !string.IsNullOrEmpty(value);
OnPropertyChanged();
}
}
Expand All @@ -154,6 +152,16 @@ public bool IsCommandStatusLabelVisible
}
}

private void OnSetColor(string colorName)
{
Color = colorName switch
{
"Blue" => Colors.Blue,
"Green" => Colors.Green,
_ => null,
};
}

private void OnCheckedChanged()
{
CheckedChangedStatus = "CheckedChanged Triggered";
Expand All @@ -171,8 +179,56 @@ private void OnCheckBoxCommand(string parameter)
}
}

public bool HasShadow
{
get => _hasShadow;
set
{
if (_hasShadow != value)
{
_hasShadow = value;
Shadow = value
? new Shadow
{
Radius = 10,
Opacity = 1.0f,
Brush = Colors.Black.AsPaint(),
Offset = new Point(5, 5)
}
: null;
OnPropertyChanged();
}
}
}

public Shadow Shadow
{
get => _shadow;
set
{
if (_shadow != value)
{
_shadow = value;
OnPropertyChanged();
}
}
}

public void Reset()
{
IsChecked = true;
Color = null;
IsEnabled = true;
IsVisible = true;
HasShadow = false;
CheckedChangedStatus = string.Empty;
CommandStatus = string.Empty;
CommandParameter = string.Empty;
}

protected void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
}

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
Loading