Skip to content

Commit 9b390c4

Browse files
authored
Merge pull request #236 from enisn/preview.13-checkbox
MAUI - Checkbox
2 parents e4f9630 + 8bbb4e0 commit 9b390c4

File tree

13 files changed

+104
-70
lines changed

13 files changed

+104
-70
lines changed

InputKit/Shared/Controls/AdvancedEntry.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@ public virtual void FocusNext()
494494
if (this.Parent is Layout parent)
495495
{
496496
int index = parent.Children.IndexOf(this);
497-
for (int i = index + 1; i < (index + 4).Clamp(0, parent.Children.Count); i++)
497+
for (int i = index + 1; i < Math.Clamp(index + 4, 0, parent.Children.Count); i++)
498498
{
499499
if (parent.Children[i] is AdvancedEntry)
500500
{

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: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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+
if(sender is Button button)
28+
{
29+
button.BackgroundColor = color;
30+
}
31+
}
32+
}
290 Bytes
Loading

src/InputKit/Handlers/IconView/IconViewHandler.Standard.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,16 @@ public partial class IconViewHandler : ViewHandler<IIconView, object>
1616

1717
static void MapSource(IIconViewHandler handler, IIconView view)
1818
{
19-
2019
}
2120

2221
static void MapFillColor(IIconViewHandler handler, IIconView view)
2322
{
23+
}
2424

25+
26+
// TODO: Remove after following issue closed https://github.com/dotnet/maui/issues/3410
27+
static void MapIsVisible(IIconViewHandler handler, IIconView view)
28+
{
2529
}
2630
}
2731
}

src/InputKit/Handlers/IconView/IconViewHandler.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using InputKit.Shared.Controls;
22
using Microsoft.Maui;
3+
using Microsoft.Maui.Controls;
34
using System;
45

56
#if __IOS__ || MACCATALYST
@@ -22,6 +23,9 @@ public partial class IconViewHandler : IIconViewHandler
2223
[nameof(IIconView.Source)] = MapSource,
2324
[nameof(IIconView.FillColor)] = MapFillColor,
2425

26+
// TODO: Remove after following issue closed https://github.com/dotnet/maui/issues/3410
27+
[nameof(View.IsVisible)] = MapIsVisible,
28+
2529
};
2630

2731
public IconViewHandler() : base(IconViewMapper)

src/InputKit/Platforms/Android/Handlers/IconViewHandler.Android.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ public static void MapFillColor(IIconViewHandler handler, IIconView view)
3333
UpdateBitmap(handler, view);
3434
}
3535

36+
// TODO: Remove after following issue closed https://github.com/dotnet/maui/issues/3410
37+
public static void MapIsVisible(IIconViewHandler handler, IIconView view)
38+
{
39+
ViewHandler.MapVisibility(handler, view);
40+
}
41+
3642
public static void UpdateBitmap(IIconViewHandler handler, IIconView view)
3743
{
3844
if (view.Source == null)

0 commit comments

Comments
 (0)