Skip to content

Commit 4b837c1

Browse files
committed
Checkbox implementation
1 parent 264f8dc commit 4b837c1

File tree

8 files changed

+74
-62
lines changed

8 files changed

+74
-62
lines changed

sandbox/SandboxMAUI/App.xaml.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55

66
namespace SandboxMAUI
77
{
8-
public partial class App : Application
9-
{
10-
public App()
11-
{
12-
InitializeComponent();
8+
public partial class App : Application
9+
{
10+
public App()
11+
{
12+
InitializeComponent();
1313

14-
MainPage = new MainPage();
15-
}
16-
}
14+
MainPage = new NavigationPage(new MainPage());
15+
}
16+
}
1717
}

sandbox/SandboxMAUI/MainPage.xaml

Lines changed: 3 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -5,50 +5,12 @@
55
BackgroundColor="{DynamicResource SecondaryColor}">
66

77
<ScrollView>
8-
<Grid RowSpacing="25" RowDefinitions="Auto,Auto,Auto,Auto,*"
8+
<StackLayout
99
Padding="{OnPlatform iOS='30,60,30,30', Default='30'}">
1010

11-
<StackLayout Grid.Row="0">
12-
<input:CheckBox Text="Option 1" Type="Material" Color="Blue" IconColor="Red" />
13-
<Label
14-
Text="Hello, World!"
15-
SemanticProperties.HeadingLevel="Level1"
16-
FontSize="32"
17-
HorizontalOptions="Center" />
18-
</StackLayout>
1911

20-
<Label
21-
Text="Welcome to .NET Multi-platform App UI"
22-
Grid.Row="1"
23-
SemanticProperties.HeadingLevel="Level1"
24-
SemanticProperties.Description="Welcome to dot net Multi platform App U I"
25-
FontSize="18"
26-
HorizontalOptions="Center" />
12+
<Button Text="CheckBox" Clicked="GoToCheckBoxPage" />
2713

28-
<Label
29-
Text="Current count: 0"
30-
Grid.Row="2"
31-
FontSize="18"
32-
FontAttributes="Bold"
33-
x:Name="CounterLabel"
34-
HorizontalOptions="Center" />
35-
36-
<Button
37-
Text="Click me"
38-
FontAttributes="Bold"
39-
Grid.Row="3"
40-
SemanticProperties.Hint="Counts the number of times you click"
41-
Clicked="OnCounterClicked"
42-
HorizontalOptions="Center" />
43-
44-
<Image Grid.Row="4"
45-
IsVisible="False"
46-
Source="dotnet_bot.png"
47-
SemanticProperties.Description="Cute dot net bot waving hi to you!"
48-
WidthRequest="250"
49-
HeightRequest="310"
50-
HorizontalOptions="Center" />
51-
52-
</Grid>
14+
</StackLayout>
5315
</ScrollView>
5416
</ContentPage>
Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,20 @@
11
using System;
22
using Microsoft.Maui.Controls;
33
using Microsoft.Maui.Essentials;
4+
using SandboxMAUI.Pages;
45

56
namespace SandboxMAUI
67
{
78
public partial class MainPage : ContentPage
89
{
9-
int count = 0;
10-
1110
public MainPage()
1211
{
1312
InitializeComponent();
1413
}
1514

16-
private void OnCounterClicked(object sender, EventArgs e)
17-
{
18-
count++;
19-
CounterLabel.Text = $"Current count: {count}";
20-
21-
SemanticScreenReader.Announce(CounterLabel.Text);
22-
}
23-
}
15+
async void GoToCheckBoxPage(System.Object sender, System.EventArgs e)
16+
{
17+
await Navigation.PushAsync(new CheckBoxPage());
18+
}
19+
}
2420
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
2+
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
3+
xmlns:input="clr-namespace:InputKit.Shared.Controls;assembly=InputKit"
4+
x:Class="SandboxMAUI.Pages.CheckBoxPage"
5+
Title="CheckBoxPage"
6+
BackgroundColor="White">
7+
<ScrollView>
8+
<StackLayout
9+
x:Name="mainLayout"
10+
Padding="25"
11+
Spacing="15">
12+
13+
<Button Text="Randomize colors" Clicked="Button_Clicked" />
14+
15+
<BoxView Color="Black" HeightRequest="1" HorizontalOptions="Fill" Margin="5,10" />
16+
17+
<input:CheckBox Text="Option 0 with Box Type" Type="Box" LabelPosition="After"/>
18+
<input:CheckBox Text="Option 1 with Check Type" Type="Check" />
19+
<input:CheckBox Text="Option 2 wity Cross Type" Type="Cross" />
20+
<input:CheckBox Text="Option 3 with Custom Type" Type="Custom" CustomIcon="ic_account_balance_black"/>
21+
<input:CheckBox Text="Option 4 with Material Type" Type="Material" />
22+
<input:CheckBox Text="Option 5 with Star Type" Type="Star"/>
23+
<input:CheckBox Text="Option 6 (Position)" Type="Check" LabelPosition="Before"/>
24+
25+
</StackLayout>
26+
</ScrollView>
27+
</ContentPage>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using System;
2+
using Microsoft.Maui.Controls;
3+
using Microsoft.Maui.Graphics;
4+
using CheckBox = InputKit.Shared.Controls.CheckBox;
5+
6+
namespace SandboxMAUI.Pages;
7+
8+
public partial class CheckBoxPage : ContentPage
9+
{
10+
public CheckBoxPage()
11+
{
12+
InitializeComponent();
13+
}
14+
Random rnd = new Random();
15+
private void Button_Clicked(object sender, EventArgs e)
16+
{
17+
var colors = typeof(Colors).GetFields();
18+
var color = (Color)colors[rnd.Next(colors.Length)].GetValue(null);
19+
foreach (var view in mainLayout.Children)
20+
{
21+
if (view is CheckBox chk)
22+
{
23+
chk.Color = color;
24+
}
25+
}
26+
}
27+
}
290 Bytes
Loading

src/InputKit/Shared/Controls/CheckBox.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,14 @@ public CheckBox()
5353
Padding = new Thickness(0, 10);
5454
Spacing = 10;
5555
frmBackground.Content = boxSelected;
56-
5756
ApplyLabelPosition(LabelPosition);
5857
ApplyIsCheckedAction = ApplyIsChecked;
5958
ApplyIsPressedAction = ApplyIsPressed;
6059
GestureRecognizers.Add(new TapGestureRecognizer
6160
{
6261
Command = new Command(() => { if (IsDisabled) return; IsChecked = !IsChecked; ExecuteCommand(); CheckChanged?.Invoke(this, new EventArgs()); ValidationChanged?.Invoke(this, new EventArgs()); }),
6362
});
63+
6464
imgSelected.BackgroundColor = Colors.Cyan;
6565

6666
imgSelected.WidthRequest = 15;
@@ -218,7 +218,7 @@ public LabelPosition LabelPosition
218218

219219
#region BindableProperties
220220
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
221-
public static readonly BindableProperty ColorProperty = BindableProperty.Create(nameof(Color), typeof(Color), typeof(CheckBox), InputKitOptions.GetAccentColor(), propertyChanged: (bo, ov, nv) => (bo as CheckBox).UpdateColors());
221+
public static readonly BindableProperty ColorProperty = BindableProperty.Create(nameof(Color), typeof(Color), typeof(CheckBox), GlobalSetting.Color, propertyChanged: (bo, ov, nv) => (bo as CheckBox).UpdateColors());
222222
public static readonly BindableProperty TextColorProperty = BindableProperty.Create(nameof(TextColor), typeof(Color), typeof(CheckBox), GlobalSetting.TextColor, propertyChanged: (bo, ov, nv) => (bo as CheckBox).TextColor = (Color)nv);
223223
public static readonly BindableProperty IconColorProperty = BindableProperty.Create(nameof(IconColor), typeof(Color), typeof(CheckBox), GlobalSetting.Color, propertyChanged: (bo, ov, nv) => (bo as CheckBox).UpdateColors());
224224
public static readonly BindableProperty IsCheckedProperty = BindableProperty.Create(nameof(IsChecked), typeof(bool), typeof(CheckBox), false, BindingMode.TwoWay, propertyChanged: (bo, ov, nv) => (bo as CheckBox).ApplyIsCheckedAction(bo as CheckBox, (bool)nv));

src/InputKit/Shared/InputKitOptions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ namespace InputKit.Shared;
55

66
public class InputKitOptions
77
{
8-
public static Func<Color> GetAccentColor { get; set; } = () => new Color(81, 43, 212);
8+
public static Func<Color> GetAccentColor { get; set; } = () => Color.FromArgb("#512bdf");
99
}

0 commit comments

Comments
 (0)