Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vNext of MauiIcons #97

Merged
merged 20 commits into from
May 6, 2024
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
36 changes: 36 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,42 @@ new MauiIcon().Icon(MaterialIcons.ABC).IconColor(Colors.Violet);
<Image Aspect="Center" Source="{mi:Cupertino Icon=ArchiveboxFill}"/>

<Label Text="{mi:Fluent Icon=Accounts}"/>

<ImageButton Source="{mi:Material Icon=AccessAlarm}"/>

<Entry Placeholder="{mi:FontAwesome Icon=AddressBook}"/>

<Button Text="{mi:SegoeFluent AdjustHologram, IconSize=Large, IconColor=Pink}" />
```

## Xaml Extension Data Binding Usage

The below example, Make Sures that BindingContext Inside the Xaml Extension is Set to Root of this Page, Likewise make sure to set the BindingContext When using Binding Inside the MauiIcons Xaml Extension, Additionally This example Binds to MyIcon and MyColor Properties Which Present in Code Behind But Not Included in this Example.
```xml
<ContentPage
x:Class="MauiIcons.Sample.BindingPage"
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:MauiIcons.Sample"
xmlns:mi="http://www.aathifmahir.com/dotnet/2022/maui/icons"
x:Name="thisRoot">
<HorizontalStackLayout>
<Label Text="{mi:Fluent BindingContext={x:Reference thisRoot}, Icon={Binding MyIcon}, IconColor={Binding MyColor}}" />
<Image>
<Image.Source>
<FontImageSource
Glyph="{mi:Fluent BindingContext={x:Reference thisRoot},
Icon={Binding MyIcon}, IconColor={Binding MyColor}}" />
</Image.Source>
</Image>

<Image Source="{mi:Fluent BindingContext={x:Reference thisRoot}, Icon={Binding MyIcon}, IconColor={Binding MyColor}}" />

<ImageButton Source="{mi:Fluent BindingContext={x:Reference thisRoot}, Icon={Binding MyIcon}, IconColor={Binding MyColor}" />

<mi:MauiIcon Icon="{mi:Fluent}" />
</HorizontalStackLayout>
</ContentPage>
```

## C# Markup Usage
Expand Down
17 changes: 11 additions & 6 deletions samples/MauiIcons.Sample/AppShell.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,20 @@

<TabBar>
<ShellContent
Title="Xaml"
ContentTemplate="{DataTemplate local:MainPage}"
Route="MainPage" Icon="{mi:Fluent Icon=Home12}">
</ShellContent>
Title="Xaml"
ContentTemplate="{DataTemplate local:MainPage}"
Icon="{mi:Fluent Icon=Home12}"
Route="MainPage" />
<ShellContent
Title="Code"
ContentTemplate="{DataTemplate local:BindingPage}"
Icon="{mi:FluentFilled Icon=BuildingHome24Filled}"
Route="MainPage" />
<ShellContent
Title="Markup"
ContentTemplate="{DataTemplate local:MarkupPage}"
Route="MainPage" Icon="{mi:FluentFilled Icon=Home12Filled}">
</ShellContent>
Icon="{mi:FluentFilled Icon=Home12Filled}"
Route="MainPage" />
</TabBar>


Expand Down
37 changes: 37 additions & 0 deletions samples/MauiIcons.Sample/BindingPage.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage
x:Class="MauiIcons.Sample.BindingPage"
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:MauiIcons.Sample"
xmlns:mi="http://www.aathifmahir.com/dotnet/2022/maui/icons"
x:Name="thisRoot"
Title="BindingPage"
x:DataType="local:BindingPage">
<ScrollView>
<VerticalStackLayout
Padding="30,0"
Spacing="25"
VerticalOptions="Center">

<HorizontalStackLayout HorizontalOptions="Center" Spacing="20">

<Label Text="{mi:Fluent BindingContext={x:Reference thisRoot}, Icon={Binding MyIcon}, IconColor={Binding MyColor}}" />
<Image>
<Image.Source>
<FontImageSource Glyph="{mi:Fluent BindingContext={x:Reference thisRoot}, Icon={Binding MyIcon}, IconColor={Binding MyColor}}" />
</Image.Source>
</Image>

<Image Source="{mi:Fluent BindingContext={x:Reference thisRoot}, Icon={Binding MyIcon}, IconColor={Binding MyColor}}" />

<ImageButton Source="{mi:Fluent BindingContext={x:Reference thisRoot}, Icon={Binding MyIcon}, IconColor={Binding MyColor}}" />

<mi:MauiIcon Icon="{mi:Fluent}" />
</HorizontalStackLayout>

<Button Clicked="Button_Clicked" Text="Change Icon and Color" />

</VerticalStackLayout>
</ScrollView>
</ContentPage>
47 changes: 47 additions & 0 deletions samples/MauiIcons.Sample/BindingPage.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using MauiIcons.Fluent;

namespace MauiIcons.Sample;

public partial class BindingPage : ContentPage
{
public BindingPage()
{
InitializeComponent();
BindingContext = this;
}

private Color _color = Colors.Red;
public Color MyColor
{
get => _color;
set
{
if (value != _color)
{
_color = value;
OnPropertyChanged();
}
}
}

private FluentIcons _icon = FluentIcons.Accessibility16;

public FluentIcons MyIcon
{
get => _icon;
set
{
if (value != _icon)
{
_icon = value;
OnPropertyChanged();
}
}
}

private void Button_Clicked(object sender, EventArgs e)
{
MyColor = MyColor == Colors.Red ? Colors.Green : Colors.Red;
MyIcon = MyIcon == FluentIcons.Accessibility16 ? FluentIcons.AddCircle24 : FluentIcons.Accessibility16;
}
}
6 changes: 6 additions & 0 deletions samples/MauiIcons.Sample/MauiIcons.Sample.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,10 @@
<PackageReference Include="CommunityToolkit.Maui.Markup" Version="3.3.0" />
</ItemGroup>

<ItemGroup>
<MauiXaml Update="BindingPage.xaml">
<Generator>MSBuild:Compile</Generator>
</MauiXaml>
</ItemGroup>

</Project>
6 changes: 3 additions & 3 deletions src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@
<PropertyGroup Condition="'$(MSBuildProjectName)' != 'MauiIcons.Sample' and $(MSBuildProjectName) != 'MauiIcons.Modules.UnitTest'">
<Title>MauiIcons</Title>
<PackageIcon>icon.png</PackageIcon>
<AssemblyVersion>2.1.5.0</AssemblyVersion>
<AssemblyFileVersion>2.1.5.0</AssemblyFileVersion>
<Version>2.1.5</Version>
<AssemblyVersion>2.2.5.0</AssemblyVersion>
<AssemblyFileVersion>2.2.5.0</AssemblyFileVersion>
<Version>2.2.5</Version>
<Product>$(AssemblyName) ($(TargetFramework))</Product>
<PackageVersion>$(Version)$(VersionSuffix)</PackageVersion>
<UseFullSemVerForNuGet>false</UseFullSemVerForNuGet>
Expand Down
18 changes: 18 additions & 0 deletions src/MauiIcons.Core/Converters/DefaultColorConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System.Globalization;

namespace MauiIcons.Core.Converters;
internal sealed class DefaultColorConverter : IValueConverter
{
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture) =>
value switch
{
null when parameter is Color color => color,
Color colorValue => colorValue,
_ => null
};

public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
Loading