Skip to content

Commit e2eabca

Browse files
Merge pull request #1 from SyncfusionExamples/checkbox_differentstates
Customize the Checkbox Appearance for Different States in .NET MAUI
2 parents a4772c7 + 1efd883 commit e2eabca

39 files changed

+9298
-1
lines changed

CheckBox/App.xaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version = "1.0" encoding = "UTF-8" ?>
2+
<Application xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
4+
xmlns:local="clr-namespace:CheckBox"
5+
x:Class="CheckBox.App">
6+
<Application.Resources>
7+
<ResourceDictionary>
8+
<ResourceDictionary.MergedDictionaries>
9+
<ResourceDictionary Source="Resources/Styles/Colors.xaml" />
10+
<ResourceDictionary Source="Resources/Styles/Styles.xaml" />
11+
</ResourceDictionary.MergedDictionaries>
12+
</ResourceDictionary>
13+
</Application.Resources>
14+
</Application>

CheckBox/App.xaml.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
namespace CheckBox
2+
{
3+
public partial class App : Application
4+
{
5+
public App()
6+
{
7+
InitializeComponent();
8+
}
9+
10+
protected override Window CreateWindow(IActivationState? activationState)
11+
{
12+
return new Window(new AppShell());
13+
}
14+
}
15+
}

CheckBox/AppShell.xaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<Shell
3+
x:Class="CheckBox.AppShell"
4+
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
5+
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
6+
xmlns:local="clr-namespace:CheckBox"
7+
Shell.FlyoutBehavior="Flyout"
8+
Title="CheckBox">
9+
10+
<ShellContent
11+
Title="Home"
12+
ContentTemplate="{DataTemplate local:MainPage}"
13+
Route="MainPage" />
14+
15+
</Shell>

CheckBox/AppShell.xaml.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
namespace CheckBox
2+
{
3+
public partial class AppShell : Shell
4+
{
5+
public AppShell()
6+
{
7+
InitializeComponent();
8+
}
9+
}
10+
}

CheckBox/CheckBox.csproj

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFrameworks>net9.0-android;net9.0-ios;net9.0-maccatalyst</TargetFrameworks>
5+
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net9.0-windows10.0.19041.0</TargetFrameworks>
6+
<!-- Uncomment to also build the tizen app. You will need to install tizen by following this: https://github.com/Samsung/Tizen.NET -->
7+
<!-- <TargetFrameworks>$(TargetFrameworks);net9.0-tizen</TargetFrameworks> -->
8+
9+
<!-- Note for MacCatalyst:
10+
The default runtime is maccatalyst-x64, except in Release config, in which case the default is maccatalyst-x64;maccatalyst-arm64.
11+
When specifying both architectures, use the plural <RuntimeIdentifiers> instead of the singular <RuntimeIdentifier>.
12+
The Mac App Store will NOT accept apps with ONLY maccatalyst-arm64 indicated;
13+
either BOTH runtimes must be indicated or ONLY macatalyst-x64. -->
14+
<!-- For example: <RuntimeIdentifiers>maccatalyst-x64;maccatalyst-arm64</RuntimeIdentifiers> -->
15+
16+
<OutputType>Exe</OutputType>
17+
<RootNamespace>CheckBox</RootNamespace>
18+
<UseMaui>true</UseMaui>
19+
<SingleProject>true</SingleProject>
20+
<ImplicitUsings>enable</ImplicitUsings>
21+
<Nullable>enable</Nullable>
22+
23+
<!-- Display name -->
24+
<ApplicationTitle>CheckBox</ApplicationTitle>
25+
26+
<!-- App Identifier -->
27+
<ApplicationId>com.companyname.checkbox</ApplicationId>
28+
29+
<!-- Versions -->
30+
<ApplicationDisplayVersion>1.0</ApplicationDisplayVersion>
31+
<ApplicationVersion>1</ApplicationVersion>
32+
33+
<!-- To develop, package, and publish an app to the Microsoft Store, see: https://aka.ms/MauiTemplateUnpackaged -->
34+
<WindowsPackageType>None</WindowsPackageType>
35+
36+
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'">15.0</SupportedOSPlatformVersion>
37+
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'maccatalyst'">15.0</SupportedOSPlatformVersion>
38+
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'">21.0</SupportedOSPlatformVersion>
39+
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</SupportedOSPlatformVersion>
40+
<TargetPlatformMinVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</TargetPlatformMinVersion>
41+
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'tizen'">6.5</SupportedOSPlatformVersion>
42+
</PropertyGroup>
43+
44+
<ItemGroup>
45+
<!-- App Icon -->
46+
<MauiIcon Include="Resources\AppIcon\appicon.svg" ForegroundFile="Resources\AppIcon\appiconfg.svg" Color="#512BD4" />
47+
48+
<!-- Splash Screen -->
49+
<MauiSplashScreen Include="Resources\Splash\splash.svg" Color="#512BD4" BaseSize="128,128" />
50+
51+
<!-- Images -->
52+
<MauiImage Include="Resources\Images\*" />
53+
<MauiImage Update="Resources\Images\dotnet_bot.png" Resize="True" BaseSize="300,185" />
54+
55+
<!-- Custom Fonts -->
56+
<MauiFont Include="Resources\Fonts\*" />
57+
58+
<!-- Raw Assets (also remove the "Resources\Raw" prefix) -->
59+
<MauiAsset Include="Resources\Raw\**" LogicalName="%(RecursiveDir)%(Filename)%(Extension)" />
60+
</ItemGroup>
61+
62+
<ItemGroup>
63+
<PackageReference Include="Microsoft.Maui.Controls" Version="$(MauiVersion)" />
64+
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="9.0.0" />
65+
<PackageReference Include="Syncfusion.Maui.Buttons" Version="*" />
66+
</ItemGroup>
67+
68+
</Project>

CheckBox/CheckBox.sln

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.12.35521.163 d17.12
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CheckBox", "CheckBox.csproj", "{1F18D5CB-510C-49F9-9F57-89576E6EAA28}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{1F18D5CB-510C-49F9-9F57-89576E6EAA28}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{1F18D5CB-510C-49F9-9F57-89576E6EAA28}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{1F18D5CB-510C-49F9-9F57-89576E6EAA28}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{1F18D5CB-510C-49F9-9F57-89576E6EAA28}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
EndGlobal

CheckBox/MainPage.xaml

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
4+
xmlns:syncfusion="clr-namespace:Syncfusion.Maui.Buttons;assembly=Syncfusion.Maui.Buttons"
5+
x:Class="CheckBox.MainPage">
6+
7+
<ContentPage.Resources>
8+
<ResourceDictionary>
9+
10+
<Style TargetType="syncfusion:SfCheckBox">
11+
<Setter Property="VisualStateManager.VisualStateGroups">
12+
<VisualStateGroupList>
13+
<VisualStateGroup x:Name="CommonStates">
14+
<VisualState x:Name="Normal">
15+
<VisualState.Setters>
16+
<Setter Property="CheckedColor" Value="#4A90E2"/>
17+
<!-- Normal Checked Color -->
18+
<Setter Property="UncheckedColor" Value="#7B8D93"/>
19+
<!-- Normal Unchecked Color -->
20+
<Setter Property="TextColor" Value="#333333"/>
21+
<!-- Normal Text Color -->
22+
<Setter Property="TickColor" Value="#FFFFFF"/>
23+
<!-- Normal Tick Color -->
24+
</VisualState.Setters>
25+
</VisualState>
26+
<VisualState x:Name="NormalNull">
27+
<VisualState.Setters>
28+
<Setter Property="CheckedColor" Value="#4A90E2"/>
29+
<!-- NormalNull Checked Color -->
30+
<Setter Property="TextColor" Value="#333333"/>
31+
<!-- NormalNull Text Color -->
32+
<Setter Property="TickColor" Value="#FFFFFF"/>
33+
<!-- NormalNull Tick Color -->
34+
</VisualState.Setters>
35+
</VisualState>
36+
<VisualState x:Name="Hover">
37+
<VisualState.Setters>
38+
<Setter Property="CheckedColor" Value="#34C759"/>
39+
<!-- Hover Checked Color -->
40+
<Setter Property="UncheckedColor" Value="#1C1B1F"/>
41+
<!-- Hover Unchecked Color -->
42+
<Setter Property="TextColor" Value="#FF9500"/>
43+
<!-- Hover Text Color -->
44+
<Setter Property="TickColor" Value="#FFFFFF"/>
45+
<!-- Hover Tick Color -->
46+
</VisualState.Setters>
47+
</VisualState>
48+
<VisualState x:Name="HoverNull">
49+
<VisualState.Setters>
50+
<Setter Property="CheckedColor" Value="#34C759"/>
51+
<!-- HoverNull Checked Color -->
52+
<Setter Property="TextColor" Value="#FF9500"/>
53+
<!-- HoverNull Text Color -->
54+
<Setter Property="TickColor" Value="#FFFFFF"/>
55+
<!-- HoverNull Tick Color -->
56+
</VisualState.Setters>
57+
</VisualState>
58+
<VisualState x:Name="Pressed">
59+
<VisualState.Setters>
60+
<Setter Property="CheckedColor" Value="#FF3B30"/>
61+
<!-- Pressed Checked Color -->
62+
<Setter Property="UncheckedColor" Value="#FF2D55"/>
63+
<!-- Pressed Unchecked Color -->
64+
<Setter Property="TextColor" Value="#FFCC00"/>
65+
<!-- Pressed Text Color -->
66+
<Setter Property="TickColor" Value="#000000"/>
67+
<!-- Pressed Tick Color -->
68+
</VisualState.Setters>
69+
</VisualState>
70+
<VisualState x:Name="PressedNull">
71+
<VisualState.Setters>
72+
<Setter Property="CheckedColor" Value="#FF3B30"/>
73+
<!-- PressedNull Checked Color -->
74+
<Setter Property="TextColor" Value="#FFCC00"/>
75+
<!-- PressedNull Text Color -->
76+
<Setter Property="TickColor" Value="#000000"/>
77+
<!-- PressedNull Tick Color -->
78+
</VisualState.Setters>
79+
</VisualState>
80+
<VisualState x:Name="Disabled">
81+
<VisualState.Setters>
82+
<Setter Property="CheckedColor" Value="#8E8E93"/>
83+
<!-- Disabled Checked Color -->
84+
<Setter Property="UncheckedColor" Value="#C7C7CC"/>
85+
<!-- Disabled Unchecked Color -->
86+
<Setter Property="TextColor" Value="#AEAEB2"/>
87+
<!-- Disabled Text Color -->
88+
<Setter Property="TickColor" Value="#D1D1D6"/>
89+
<!-- Disabled Tick Color -->
90+
</VisualState.Setters>
91+
</VisualState>
92+
<VisualState x:Name="DisabledNull">
93+
<VisualState.Setters>
94+
<Setter Property="CheckedColor" Value="#8E8E93"/>
95+
<!-- DisabledNull Checked Color -->
96+
<Setter Property="UncheckedColor" Value="#C7C7CC"/>
97+
<!-- DisabledNull Unchecked Color -->
98+
<Setter Property="TextColor" Value="#AEAEB2"/>
99+
<!-- DisabledNull Text Color -->
100+
<Setter Property="TickColor" Value="#D1D1D6"/>
101+
<!-- DisabledNull Tick Color -->
102+
</VisualState.Setters>
103+
</VisualState>
104+
</VisualStateGroup>
105+
</VisualStateGroupList>
106+
</Setter>
107+
</Style>
108+
109+
</ResourceDictionary>
110+
</ContentPage.Resources>
111+
112+
<StackLayout Padding="20">
113+
<Label x:Name="label" Margin="10" Text="Pizza Toppings"/>
114+
<syncfusion:SfCheckBox x:Name="selectAll" Text="Select All" IsThreeState="True" IsChecked="{x:Null}" StateChanged="SelectAll_StateChanged"/>
115+
<syncfusion:SfCheckBox x:Name="pepperoni" Text="Pepperoni" StateChanged="CheckBox_StateChanged" Margin="30,0"/>
116+
<syncfusion:SfCheckBox x:Name="beef" Text="Beef" IsChecked="True" StateChanged="CheckBox_StateChanged" Margin="30,0" IsEnabled="False"/>
117+
<syncfusion:SfCheckBox x:Name="mushroom" Text="Mushrooms" StateChanged="CheckBox_StateChanged" Margin="30,0"/>
118+
<syncfusion:SfCheckBox x:Name="onion" Text="Onions" IsChecked="True" StateChanged="CheckBox_StateChanged" Margin="30,0"/>
119+
</StackLayout>
120+
</ContentPage>
121+
122+

CheckBox/MainPage.xaml.cs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
namespace CheckBox
2+
{
3+
public partial class MainPage : ContentPage
4+
{
5+
6+
7+
public MainPage()
8+
{
9+
InitializeComponent();
10+
}
11+
bool skip = false;
12+
private void SelectAll_StateChanged(object sender, Syncfusion.Maui.Buttons.StateChangedEventArgs e)
13+
{
14+
if (!skip)
15+
{
16+
skip = true;
17+
pepperoni.IsChecked = beef.IsChecked = mushroom.IsChecked = onion.IsChecked = e.IsChecked;
18+
skip = false;
19+
}
20+
}
21+
22+
private void CheckBox_StateChanged(object sender, Syncfusion.Maui.Buttons.StateChangedEventArgs e)
23+
{
24+
if (!skip)
25+
{
26+
skip = true;
27+
if (pepperoni.IsChecked.Value && beef.IsChecked.Value && mushroom.IsChecked.Value && onion.IsChecked.Value)
28+
selectAll.IsChecked = true;
29+
else if (!pepperoni.IsChecked.Value && !beef.IsChecked.Value && !mushroom.IsChecked.Value && !onion.IsChecked.Value)
30+
selectAll.IsChecked = false;
31+
else
32+
selectAll.IsChecked = null;
33+
skip = false;
34+
}
35+
}
36+
37+
}
38+
39+
}

CheckBox/MauiProgram.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using Microsoft.Extensions.Logging;
2+
using Syncfusion.Maui.Core.Hosting;
3+
namespace CheckBox
4+
{
5+
public static class MauiProgram
6+
{
7+
public static MauiApp CreateMauiApp()
8+
{
9+
var builder = MauiApp.CreateBuilder();
10+
builder
11+
.UseMauiApp<App>()
12+
.ConfigureSyncfusionCore()
13+
.ConfigureFonts(fonts =>
14+
{
15+
fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
16+
fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
17+
});
18+
19+
#if DEBUG
20+
builder.Logging.AddDebug();
21+
#endif
22+
23+
return builder.Build();
24+
}
25+
}
26+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
3+
<application android:allowBackup="true" android:icon="@mipmap/appicon" android:roundIcon="@mipmap/appicon_round" android:supportsRtl="true"></application>
4+
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
5+
<uses-permission android:name="android.permission.INTERNET" />
6+
</manifest>

0 commit comments

Comments
 (0)