Skip to content

Commit

Permalink
Merge pull request #428 from AndreasReitberger/421-add-syncfusionmaui…
Browse files Browse the repository at this point in the history
…buttons-and-corresponding-styles

Added styles for the `SfSegmentedControl`
  • Loading branch information
AndreasReitberger authored Feb 9, 2024
2 parents 4ec5e1b + ae67f29 commit 40186e7
Show file tree
Hide file tree
Showing 20 changed files with 385 additions and 18 deletions.
4 changes: 2 additions & 2 deletions common.props
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
</ItemGroup>
-->
<ItemGroup>
<PackageReference Include="Microsoft.Maui.Controls" Version="$(MauiVersion)" />
<PackageReference Include="Microsoft.Maui.Controls.Compatibility" Version="$(MauiVersion)" />
<PackageReference Include="Microsoft.Maui.Controls" Version="8.0.6" />
<PackageReference Include="Microsoft.Maui.Controls.Compatibility" Version="8.0.6" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="8.0.0" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" PrivateAssets="All"/>
</ItemGroup>
Expand Down
5 changes: 5 additions & 0 deletions src/SharedMauiXamlStylesLibrary.SampleApp/AppShell.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@
ContentTemplate="{DataTemplate views:EntryPage}"
Route="EntryPage" />

<ShellContent
Title="SfSegmentedControl"
ContentTemplate="{DataTemplate views:SfSegmentedControlPage}"
Route="SfSegmentedControlPage" />

<ShellContent
Title="TabView"
ContentTemplate="{DataTemplate views:TabViewPage}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public static MauiAppBuilder RegisterMainViewModels(this MauiAppBuilder builder)
builder.Services.AddSingleton<LabesPageViewModel>();
builder.Services.AddSingleton<EntryPageViewModel>();
builder.Services.AddSingleton<ButtonsPageViewModel>();
builder.Services.AddSingleton<SfSegmentedControlPageViewModel>();
builder.Services.AddSingleton<TabViewPageViewModel>();
return builder;
}
Expand All @@ -47,6 +48,7 @@ public static MauiAppBuilder RegisterMainViews(this MauiAppBuilder builder)
builder.Services.AddSingleton<ButtonsPage>();
builder.Services.AddSingleton<EntryPage>();
builder.Services.AddSingleton<LabelsPage>();
builder.Services.AddSingleton<SfSegmentedControlPage>();
builder.Services.AddSingleton<TabViewPage>();
return builder;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@
</ItemGroup>

<ItemGroup>
<Compile Update="Views\SfSegmentedControlPage.xaml.cs">
<DependentUpon>SfSegmentedControlPage.xaml</DependentUpon>
</Compile>
<Compile Update="Views\EntryPage.xaml.cs">
<DependentUpon>EntryPage.xaml</DependentUpon>
</Compile>
Expand Down Expand Up @@ -87,5 +90,8 @@
<MauiXaml Update="Views\LabelsPage.xaml">
<Generator>MSBuild:Compile</Generator>
</MauiXaml>
<MauiXaml Update="Views\SfSegmentedControlPage.xaml">
<Generator>MSBuild:Compile</Generator>
</MauiXaml>
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using CommunityToolkit.Mvvm.ComponentModel;
using System.Collections.ObjectModel;

namespace SharedMauiXamlStylesLibrary.SampleApp.ViewModels
{
public partial class SfSegmentedControlPageViewModel : BaseViewModel
{

#region Properties

[ObservableProperty]
ObservableCollection<string> sizes = [
"S", "M", "L", "XL", "XXL"
];

[ObservableProperty]
int selectedSizeIndex = 0;
partial void OnSelectedSizeIndexChanged(int value) => SelectedSize = Sizes[value];

[ObservableProperty]
string selectedSize = string.Empty;
#endregion

#region Constructor, LoadSettings

public SfSegmentedControlPageViewModel(IDispatcher dispatcher, IServiceProvider provider) : base(dispatcher, provider)
{
Dispatcher = dispatcher;
UpdateVersionBuild();
}

#endregion

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?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"
x:Class="SharedMauiXamlStylesLibrary.SampleApp.Views.SfSegmentedControlPage"

xmlns:viewModels="clr-namespace:SharedMauiXamlStylesLibrary.SampleApp.ViewModels"

xmlns:converters="clr-namespace:AndreasReitberger.Shared.Core.Converters;assembly=SharedMauiCoreLibrary"

xmlns:icons="clr-namespace:AndreasReitberger.Shared.FontIcons;assembly=SharedMauiXamlStylesLibrary"
xmlns:iconsSyncfusion="clr-namespace:AndreasReitberger.Shared.Syncfusion.FontIcons;assembly=SharedMauiXamlStylesLibrary.Syncfusion"
xmlns:buttons="clr-namespace:Syncfusion.Maui.Buttons;assembly=Syncfusion.Maui.Buttons"

Title="SfSegmentedControlPage"
Style="{StaticResource Style.Core.ContentPage.Default}"
x:DataType="viewModels:SfSegmentedControlPageViewModel"
>
<ContentPage.Resources>
<converters:BrushToBlackWhiteConverter x:Key="BrushToBlackWhiteConverter" />
</ContentPage.Resources>
<ScrollView>
<VerticalStackLayout>
<Label
Margin="2,16"
Text="Segmented Control (Syncfusion)"
VerticalTextAlignment="Center"
HorizontalTextAlignment="Center"
Style="{StaticResource Style.Core.Label.Default}"
/>
<!--
Style="{StaticResource Style.Syncfusion.SfSegmentedControl.Default}"
-->
<buttons:SfSegmentedControl
Margin="4,16"
ItemsSource="{Binding Sizes}"
SelectedIndex="{Binding SelectedSizeIndex, Mode=TwoWay}"
Style="{StaticResource Style.Syncfusion.SfSegmentedControl.Default}"
/>

<buttons:SfSegmentedControl
Margin="4,16"
ItemsSource="{Binding Sizes}"
SelectedIndex="{Binding SelectedSizeIndex, Mode=TwoWay}"
Style="{StaticResource Style.Syncfusion.SfSegmentedControl.Borderless}"
/>

</VerticalStackLayout>
</ScrollView>
</ContentPage>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using SharedMauiXamlStylesLibrary.SampleApp.ViewModels;

namespace SharedMauiXamlStylesLibrary.SampleApp.Views;

public partial class SfSegmentedControlPage : ContentPage
{
public SfSegmentedControlPage(SfSegmentedControlPageViewModel viewModel)
{
InitializeComponent();
BindingContext = viewModel;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
<?xml version="1.0" encoding="utf-8" ?>
<?xaml-comp compile="true" ?>
<ResourceDictionary
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"

xmlns:converters="clr-namespace:AndreasReitberger.Shared.Core.Converters;assembly=SharedMauiCoreLibrary"
xmlns:shared="clr-namespace:AndreasReitberger.Shared;assembly=SharedMauiXamlStylesLibrary"
xmlns:icons="clr-namespace:AndreasReitberger.Shared.Syncfusion.FontIcons"
xmlns:iconsCore="clr-namespace:AndreasReitberger.Shared.FontIcons;assembly=SharedMauiXamlStylesLibrary"

xmlns:core="clr-namespace:Syncfusion.Maui.Core;assembly=Syncfusion.Maui.Core"
xmlns:buttons="clr-namespace:Syncfusion.Maui.Buttons;assembly=Syncfusion.Maui.Buttons"
>
<ResourceDictionary.MergedDictionaries>
<shared:Colors />
<shared:Fonts />
<ResourceDictionary Source="/Resources/Themes/SharedFonts.xaml" />
</ResourceDictionary.MergedDictionaries>

<converters:BrushToBlackWhiteConverter x:Key="BrushToBlackWhiteConverter"/>

<!-- Docs: https://help.syncfusion.com/maui/button/overview -->
<Style x:Key="Style.Syncfusion.SfButton.Default" TargetType="buttons:SfButton">
<Setter Property="FontFamily" Value="{StaticResource MontserratSemiBold}" />
<Setter Property="Background" Value="{AppThemeBinding Light={StaticResource White}, Dark={StaticResource Black}}" />
<Setter Property="TextColor" Value="{Binding Source={RelativeSource Self}, Path=Background, Converter={StaticResource BrushToBlackWhiteConverter}}" />
<Setter Property="FontSize" Value="Small" />
<Setter Property="VisualStateManager.VisualStateGroups">
<VisualStateGroupList>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Normal">
<VisualState.Setters>
<Setter Property="Background" Value="{DynamicResource PrimaryColor}"/>
<Setter Property="TextColor" Value="{Binding Source={RelativeSource Self}, Path=Background, Converter={StaticResource BrushToBlackWhiteConverter}}" />
</VisualState.Setters>
</VisualState>
<VisualState x:Name="Disabled">
<VisualState.Setters>
<Setter Property="Background" Value="{AppThemeBinding Light={StaticResource LightGray}, Dark={StaticResource DarkGray}}" />
<Setter Property="TextColor" Value="{AppThemeBinding Light={StaticResource DarkGray}, Dark={StaticResource LightGray}}" />
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
</VisualStateGroupList>
</Setter>
</Style>

<Style TargetType="buttons:SfButton" BasedOn="{StaticResource Style.Syncfusion.SfButton.Default}"/>

<Style x:Key="Style.Syncfusion.SfButton.Icon" TargetType="buttons:SfButton" BasedOn="{StaticResource Style.Syncfusion.SfButton.Default}">
<Setter Property="Background" Value="{StaticResource Transparent}" />
<Setter Property="TextColor" Value="{AppThemeBinding Light={StaticResource Gray600}, Dark={StaticResource Gray400}}" />
<Setter Property="FontFamily" Value="{StaticResource FontIcons}" />
<Setter Property="FontSize" Value="{OnIdiom Desktop=Medium, Default=Large}" />
<Setter Property="HorizontalTextAlignment" Value="Center" />
<Setter Property="VerticalTextAlignment" Value="Center" />
<Setter Property="HeightRequest" Value="{OnIdiom Phone=40, Default=60}" />
<Setter Property="WidthRequest" Value="{OnIdiom Phone=40, Default=60}" />
</Style>

<Style x:Key="Style.Syncfusion.SfButton.Icon.MaterialDesign" TargetType="buttons:SfButton" BasedOn="{StaticResource Style.Syncfusion.SfButton.Icon}">
<Setter Property="FontFamily" Value="{StaticResource MaterialDesignIcons}" />
<Setter Property="FontSize" Value="{OnIdiom Desktop=32, Tablet=26, Default=22}" />
</Style>

<Style x:Key="Style.Syncfusion.SfButton.IconRound.MaterialDesign" TargetType="buttons:SfButton">
<Setter Property="Background" Value="{StaticResource Transparent}" />
<Setter Property="TextColor" Value="{AppThemeBinding Light={StaticResource Gray600}, Dark={StaticResource Gray400}}" />
<Setter Property="FontFamily" Value="{StaticResource MaterialDesignIcons}" />
<Setter Property="FontSize" Value="{OnIdiom Desktop=32, Tablet=32, Phone=22, Default=22}" />
<Setter Property="HorizontalTextAlignment" Value="Center" />
<Setter Property="VerticalTextAlignment" Value="Center" />
<Setter Property="HeightRequest" Value="{OnIdiom Phone=40, Default=60}" />
<Setter Property="WidthRequest" Value="{OnIdiom Phone=40, Default=60}" />
<Setter Property="CornerRadius" Value="{OnIdiom Phone=20, Default=30}" />
</Style>

<Style x:Key="Style.Syncfusion.SfButton.IconRound.EmergencyStop" TargetType="buttons:SfButton" BasedOn="{StaticResource Style.Syncfusion.SfButton.IconRound.MaterialDesign}">
<Setter Property="Text" Value="{x:Static iconsCore:MaterialIcons.HandBackRight}" />
<Setter Property="Background" Value="{StaticResource Red}" />
<Setter Property="TextColor" Value="{StaticResource White}" />
<Setter Property="Stroke" Value="{StaticResource Yellow}" />
<Setter Property="StrokeThickness" Value="3" />
<Setter Property="HeightRequest" Value="{OnIdiom Phone=50, Default=70}" />
<Setter Property="WidthRequest" Value="{OnIdiom Phone=50, Default=70}" />
<Setter Property="CornerRadius" Value="{OnIdiom Phone=25, Default=35}" />
</Style>

</ResourceDictionary>
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?xml version="1.0" encoding="utf-8" ?>
<?xaml-comp compile="true" ?>
<ResourceDictionary
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"

xmlns:converters="clr-namespace:AndreasReitberger.Shared.Core.Converters;assembly=SharedMauiCoreLibrary"
xmlns:core="clr-namespace:Syncfusion.Maui.Core;assembly=Syncfusion.Maui.Core"
xmlns:buttons="clr-namespace:Syncfusion.Maui.Buttons;assembly=Syncfusion.Maui.Buttons"
xmlns:shared="clr-namespace:AndreasReitberger.Shared;assembly=SharedMauiXamlStylesLibrary"
>
<ResourceDictionary.MergedDictionaries>
<shared:Colors />
<shared:Fonts />
<ResourceDictionary Source="/Resources/Themes/SharedFonts.xaml" />
</ResourceDictionary.MergedDictionaries>

<converters:BrushToBlackWhiteConverter x:Key="BrushToBlackWhiteConverter"/>

<!-- Docs: https://help.syncfusion.com/maui/segmented-control/overviews -->
<Style x:Key="Style.Syncfusion.SfSegmentedControl.Default" TargetType="buttons:SfSegmentedControl">
<Setter Property="TextStyle">
<Setter.Value>
<buttons:SegmentTextStyle
FontSize="{OnIdiom Phone=14, Default=18}"
FontFamily="{StaticResource MontserratBold}"
TextColor="{AppThemeBinding Light={StaticResource Black}, Dark={StaticResource White}}"
/>
</Setter.Value>
</Setter>
<!--
Causes exception => Operation is not valid due to the current state of the object.
TextColor="{Binding Source={RelativeSource Self}, Path=Background, Converter={StaticResource BrushToBlackWhiteConverter}}"
-->
<Setter Property="SelectionIndicatorSettings">
<Setter.Value>
<buttons:SelectionIndicatorSettings
Background="{DynamicResource PrimaryColor}"
TextColor="{AppThemeBinding Light={StaticResource Black}, Dark={StaticResource White}}"
/>
</Setter.Value>
</Setter>

<Setter Property="StrokeThickness" Value="2" />
<Setter Property="Stroke" Value="{AppThemeBinding Light={StaticResource Gray200}, Dark={StaticResource Gray800}}" />
<Setter Property="CornerRadius" Value="8" />
<Setter Property="SegmentCornerRadius" Value="0" />
</Style>

<Style x:Key="Style.Syncfusion.SfSegmentedControl.Printers" TargetType="buttons:SfSegmentedControl" BasedOn="{StaticResource Style.Syncfusion.SfSegmentedControl.Default}">
<Setter Property="SegmentBackground" Value="{AppThemeBinding Light={StaticResource White}, Dark={StaticResource Black}}" />
<Setter Property="Stroke" Value="{AppThemeBinding Light={StaticResource White}, Dark={StaticResource Black}}" />
<Setter Property="SegmentWidth" Value="48" />
</Style>

<Style x:Key="Style.Syncfusion.SfSegmentedControl.Borderless" TargetType="buttons:SfSegmentedControl" BasedOn="{StaticResource Style.Syncfusion.SfSegmentedControl.Default}">
<Setter Property="TextStyle">
<Setter.Value>
<buttons:SegmentTextStyle
FontSize="{OnIdiom Phone=10, Default=14}"
FontFamily="{StaticResource MontserratBold}"
TextColor="{AppThemeBinding Light={StaticResource Black}, Dark={StaticResource White}}"
/>
</Setter.Value>
</Setter>
<!--
Causes exception => Operation is not valid due to the current state of the object.
TextColor="{Binding Source={RelativeSource Self}, Path=Background, Converter={StaticResource BrushToBlackWhiteConverter}}"
-->
<Setter Property="SelectionIndicatorSettings">
<Setter.Value>
<buttons:SelectionIndicatorSettings
Background="{DynamicResource PrimaryColor}"
TextColor="{AppThemeBinding Light={StaticResource Black}, Dark={StaticResource White}}"
SelectionIndicatorPlacement="Border"
/>
</Setter.Value>
</Setter>
<Setter Property="StrokeThickness" Value="0" />
<Setter Property="SegmentWidth" Value="{OnIdiom Phone=32, Default=64}" />
<Setter Property="CornerRadius" Value="{OnIdiom Phone=16, Default=32}" />
<Setter Property="SegmentCornerRadius" Value="{OnIdiom Phone=16, Default=32}" />
</Style>
</ResourceDictionary>
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

<Style x:Key="Style.Syncfusion.SfTreeView.Default" TargetType="treeView:SfTreeView">
<Setter Property="SelectionForeground" Value="{DynamicResource PrimaryColor}"/>
<Setter Property="SelectionBackground" Value="{AppThemeBinding Light={StaticResource Gray100}, Dark={StaticResource Gray950}}" />
<Setter Property="SelectionBackground" Value="{AppThemeBinding Light={StaticResource Gray200}, Dark={StaticResource Gray800}}" />
<Setter Property="Background" Value="{AppThemeBinding Light={StaticResource White}, Dark={StaticResource Black}}" />
</Style>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<shared:Colors />
<shared:Fonts />

<ResourceDictionary Source="/Resources/Themes/SharedConverters.xaml" />
<ResourceDictionary Source="/Resources/Themes/SharedFonts.xaml" />
<!-- Templates must come for styles! -->
<ResourceDictionary Source="/Resources/Themes/SharedTemplates.xaml" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8" ?>
<ResourceDictionary
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="AndreasReitberger.Shared.Syncfusion.SharedConverters"

xmlns:converters="clr-namespace:AndreasReitberger.Shared.Syncfusion.Converters"
>
<!-- Syncfusion Converters -->
<converters:BooleanToBadgeIconConverter x:Key="BooleanToBadgeIconConverter" />
<converters:DictionaryToChartSeriesCollectionConverter x:Key="DictionaryToChartSeriesCollectionConverter" />
</ResourceDictionary>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace AndreasReitberger.Shared.Syncfusion;

public partial class SharedConverters
{
public SharedConverters()
{
InitializeComponent();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<ResourceDictionary Source="/Resources/Themes/Controls/SfAutoComplete.xaml" />
<ResourceDictionary Source="/Resources/Themes/Controls/SfBadgeView.xaml" />
<ResourceDictionary Source="/Resources/Themes/Controls/SfBusyIndicator.xaml" />
<ResourceDictionary Source="/Resources/Themes/Controls/SfButton.xaml" />
<ResourceDictionary Source="/Resources/Themes/Controls/SfCartesianChart.xaml" />
<ResourceDictionary Source="/Resources/Themes/Controls/SfChips.xaml" />
<ResourceDictionary Source="/Resources/Themes/Controls/SfComboBox.xaml" />
Expand All @@ -20,9 +21,10 @@
<ResourceDictionary Source="/Resources/Themes/Controls/SfNumericEntry.xaml" />
<ResourceDictionary Source="/Resources/Themes/Controls/SfPicker.xaml" />
<ResourceDictionary Source="/Resources/Themes/Controls/SfRadialGauge.xaml" />
<ResourceDictionary Source="/Resources/Themes/Controls/SfSlider.xaml" />
<ResourceDictionary Source="/Resources/Themes/Controls/SfRating.xaml" />
<ResourceDictionary Source="/Resources/Themes/Controls/SfRangeSlider.xaml" />
<ResourceDictionary Source="/Resources/Themes/Controls/SfSegmentedControl.xaml" />
<ResourceDictionary Source="/Resources/Themes/Controls/SfSlider.xaml" />
<ResourceDictionary Source="/Resources/Themes/Controls/SfTabView.xaml" />
<ResourceDictionary Source="/Resources/Themes/Controls/SfTextInputLayout.xaml" />
<ResourceDictionary Source="/Resources/Themes/Controls/SfTreeView.xaml" />
Expand Down
Loading

0 comments on commit 40186e7

Please sign in to comment.