Skip to content

Commit

Permalink
Merge pull request #96 from AathifMahir/Binding_Extension
Browse files Browse the repository at this point in the history
Data Binding Support for Xaml Markup Extensions
  • Loading branch information
AathifMahir committed May 5, 2024
2 parents 9a701ce + c400400 commit 0152816
Show file tree
Hide file tree
Showing 21 changed files with 292 additions and 112 deletions.
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.0.0</AssemblyVersion>
<AssemblyFileVersion>2.2.0.0</AssemblyFileVersion>
<Version>2.2.0-pre</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();
}
}

0 comments on commit 0152816

Please sign in to comment.