{"id":798,"date":"2023-01-30T16:59:36","date_gmt":"2023-01-30T16:59:36","guid":{"rendered":"https:\/\/learnmobiledevelopment.com\/?p=798"},"modified":"2023-01-30T17:23:50","modified_gmt":"2023-01-30T17:23:50","slug":"apply-color-to-images-and-icons-in-maui","status":"publish","type":"post","link":"https:\/\/learnmobiledevelopment.com\/index.php\/2023\/01\/30\/apply-color-to-images-and-icons-in-maui\/","title":{"rendered":"How to apply color to Images and Icons in MAUI"},"content":{"rendered":"\n<p>Sometimes we need the same image in two different colors (eg : enable\/disable image) to show based on some conditions. So taking two images is not the right way. We need to use one image instead of two and based on some condition we need to change the color of the same image. So In this article, I\u2019m going to show you how to apply color to images and icons in MAUI.<\/p>\n\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p style=\"font-size:25px\"><strong>Let\u2019s Start<\/strong><\/p>\n\n\n\n<p>The MAUI community toolkit provides us with <strong>IconTintColorBehavior<\/strong> to change the color of an image and icon.<\/p>\n\n\n\n<p>In this sample demo we will use&nbsp;<strong><a href=\"https:\/\/www.nuget.org\/packages\/CommunityToolkit.Maui\/\" target=\"_blank\" rel=\"noreferrer noopener\">CommunityToolkit.Maui<\/a><\/strong>&nbsp;nuget package.<\/p>\n\n\n\n<p class=\"has-medium-font-size\"><strong>CommunityToolkit.Maui<\/strong><\/p>\n\n\n\n<p>CommunityToolkit.Maui&nbsp;is a collection of Converters, Behaviours, Animations, Custom Views, Effects, Helpers etc. It simplifies the developers task when building Android, iOS, macOS and WinUI applications using MAUI.<\/p>\n\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p class=\"has-medium-font-size\"><strong>1 \u2013 Install CommunityToolkit.Maui&nbsp;nuget package<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"606\" src=\"https:\/\/learnmobiledevelopment.com\/wp-content\/uploads\/2022\/12\/ExpanderinMAUI-e1670421322529-1024x606.png\" alt=\"Expander in MAUI\" class=\"wp-image-422\" srcset=\"https:\/\/learnmobiledevelopment.com\/wp-content\/uploads\/2022\/12\/ExpanderinMAUI-e1670421322529-1024x606.png 1024w, https:\/\/learnmobiledevelopment.com\/wp-content\/uploads\/2022\/12\/ExpanderinMAUI-e1670421322529-300x178.png 300w, https:\/\/learnmobiledevelopment.com\/wp-content\/uploads\/2022\/12\/ExpanderinMAUI-e1670421322529-768x455.png 768w, https:\/\/learnmobiledevelopment.com\/wp-content\/uploads\/2022\/12\/ExpanderinMAUI-e1670421322529-1536x909.png 1536w, https:\/\/learnmobiledevelopment.com\/wp-content\/uploads\/2022\/12\/ExpanderinMAUI-e1670421322529-850x503.png 850w, https:\/\/learnmobiledevelopment.com\/wp-content\/uploads\/2022\/12\/ExpanderinMAUI-e1670421322529.png 1802w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p class=\"has-medium-font-size\"><strong>2 \u2013 In order to use the .NET MAUI Community Toolkit we need to call the extension method in MauiProgram.cs&nbsp;file as follows<\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\" data-enlighter-theme=\"dracula\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">using CommunityToolkit.Maui;\nusing Microsoft.Extensions.Logging;\n\nnamespace MAUIImageTintingSample;\n\npublic static class MauiProgram\n{\n    public static MauiApp CreateMauiApp()\n    {\n        var builder = MauiApp.CreateBuilder();\n        builder\n            .UseMauiApp&lt;App>()\n            .UseMauiCommunityToolkit()\n            .ConfigureFonts(fonts =>\n            {\n                fonts.AddFont(\"OpenSans-Regular.ttf\", \"OpenSansRegular\");\n                fonts.AddFont(\"OpenSans-Semibold.ttf\", \"OpenSansSemibold\");\n            });\n\n#if DEBUG\n        builder.Logging.AddDebug();\n#endif\n\n        return builder.Build();\n    }\n}<\/pre>\n\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p class=\"has-medium-font-size\"><strong>3 &#8211; Setting up the UI<\/strong><\/p>\n\n\n\n<p class=\"has-medium-font-size\"><strong>3.1 &#8211; Create a MainPage.xaml<\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"xml\" data-enlighter-theme=\"dracula\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;?xml version=\"1.0\" encoding=\"utf-8\" ?>\n&lt;ContentPage xmlns=\"http:\/\/schemas.microsoft.com\/dotnet\/2021\/maui\"\n             xmlns:x=\"http:\/\/schemas.microsoft.com\/winfx\/2009\/xaml\"\n             x:Class=\"MAUIImageTintingSample.MainPage\"\n             xmlns:vm=\"clr-namespace:MAUIImageTintingSample\"\n             xmlns:toolkit=\"http:\/\/schemas.microsoft.com\/dotnet\/2022\/maui\/toolkit\"\n             x:Name=\"MainContainer\">\n\n    &lt;ContentPage.BindingContext>\n        &lt;vm:MainPageViewModel \/>\n    &lt;\/ContentPage.BindingContext>\n\n    &lt;ScrollView>\n        &lt;VerticalStackLayout\n            Spacing=\"25\"\n            Padding=\"20,10\">\n\n            &lt;Image\n                Source=\"dotnet_bot.png\"\n                HeightRequest=\"200\"\n                vm:TintColorBehavior.AttachBehavior=\"{Binding IsAttached}\"\n                HorizontalOptions=\"Center\"\/>\n\n            &lt;HorizontalStackLayout Spacing=\"10\" HorizontalOptions=\"CenterAndExpand\">\n\n                &lt;Image Source=\"camera.png\" vm:TintColorBehavior.AttachBehavior=\"{Binding IsAttached}\"\/>\n\n                &lt;Image Source=\"heart.png\" vm:TintColorBehavior.AttachBehavior=\"{Binding IsAttached}\"\/>\n\n                &lt;Image Source=\"home.png\" vm:TintColorBehavior.AttachBehavior=\"{Binding IsAttached}\"\/>\n\n                &lt;Image Source=\"settings.png\" vm:TintColorBehavior.AttachBehavior=\"{Binding IsAttached}\"\/>\n\n                &lt;Image Source=\"user.png\" vm:TintColorBehavior.AttachBehavior=\"{Binding IsAttached}\"\/>\n\n            &lt;\/HorizontalStackLayout>\n\n            &lt;FlexLayout\n                x:Name=\"StackColorList\"\n                AlignItems=\"Center\"\n                BindableLayout.ItemsSource=\"{Binding Colors}\"\n                Direction=\"Row\"\n                FlexLayout.AlignSelf=\"Center\"\n                HorizontalOptions=\"FillAndExpand\"\n                JustifyContent=\"Center\"\n                Wrap=\"Wrap\">\n                &lt;BindableLayout.ItemTemplate>\n                    &lt;DataTemplate>\n                        &lt;Button\n                            BackgroundColor=\"{Binding Color}\"\n                            BorderColor=\"Transparent\"\n                            BorderWidth=\"2\"\n                            Command=\"{Binding BindingContext.ColorItemClickedCommand, Source={x:Reference MainContainer}}\"\n                            CommandParameter=\"{Binding .}\"\n                            CornerRadius=\"0\"\n                            HeightRequest=\"100\"\n                            WidthRequest=\"100\">\n                            &lt;Button.Triggers>\n                                &lt;DataTrigger\n                                    Binding=\"{Binding IsSelected}\"\n                                    TargetType=\"Button\"\n                                    Value=\"True\">\n                                    &lt;Setter Property=\"BorderColor\" Value=\"Red\" \/>\n                                &lt;\/DataTrigger>\n                            &lt;\/Button.Triggers>\n                        &lt;\/Button>\n                    &lt;\/DataTemplate>\n                &lt;\/BindableLayout.ItemTemplate>\n            &lt;\/FlexLayout>\n\n            &lt;Button\n                x:Name=\"CounterBtn\"\n                Text=\"Change Image Color\"\n                Command=\"{Binding ChangeImageTintColorCommand}\"\n                HorizontalOptions=\"Center\" \/>\n\n        &lt;\/VerticalStackLayout>\n    &lt;\/ScrollView>\n\n&lt;\/ContentPage><\/pre>\n\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<ul class=\"wp-block-list\">\n<li>As in the above <strong>MainPage.xaml<\/strong> I have used a bindable layout to show a list of colors and button to change the images color.<\/li>\n<\/ul>\n\n\n\n<ul class=\"wp-block-list\">\n<li>So when a user selects a color from a list and clicks on the change image color button then that picked color will be applied to the images.<\/li>\n<\/ul>\n\n\n\n<ul class=\"wp-block-list\">\n<li>And I have also created a <strong>TintColorBehavior<\/strong> for attaching\/detaching the <strong>IconTintColorBehavior<\/strong> at runtime.<\/li>\n<\/ul>\n\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p class=\"has-medium-font-size\"><strong>3.2 &#8211; Create a TintColorBehavior<\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\" data-enlighter-theme=\"dracula\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">using CommunityToolkit.Maui.Behaviors;\n\nnamespace MAUIImageTintingSample\n{\n    public class TintColorBehavior : Behavior&lt;Image>\n    {\n        public static readonly BindableProperty AttachBehaviorProperty =\n       BindableProperty.CreateAttached(\"AttachBehavior\", typeof(bool), typeof(TintColorBehavior), false, propertyChanged: OnAttachBehaviorChanged);\n\n        public static bool GetAttachBehavior(BindableObject view)\n        {\n            return (bool)view.GetValue(AttachBehaviorProperty);\n        }\n\n        public static void SetAttachBehavior(BindableObject view, bool value)\n        {\n            view.SetValue(AttachBehaviorProperty, value);\n        }\n\n        static void OnAttachBehaviorChanged(BindableObject view, object oldValue, object newValue)\n        {\n            var image = view as Image;\n            if (image == null)\n                return;\n\n            bool attachBehavior = (bool)newValue;\n            if (attachBehavior)\n            {\n                image.Behaviors.Add(new IconTintColorBehavior() { TintColor = (image.BindingContext as MainPageViewModel).Color });\n            }\n            else\n            {\n                var toRemove = image.Behaviors.FirstOrDefault(b => b is IconTintColorBehavior);\n                if (toRemove != null)\n                {\n                    image.Behaviors.Remove(toRemove);\n                }\n            }\n        }\n    }\n}<\/pre>\n\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<ul class=\"wp-block-list\">\n<li>As in the above <strong>TintColorBehavior<\/strong> behavior, I have created an attached property which is used for attaching or detaching the behavior from viewmodel.<\/li>\n<\/ul>\n\n\n\n<ul class=\"wp-block-list\">\n<li>So when the attached property gets changed then the <strong>OnAttachBehaviorChanged<\/strong> method gets executed.<\/li>\n<\/ul>\n\n\n\n<ul class=\"wp-block-list\">\n<li>And in this method based on the value, I am adding\/removing the <strong>IconTintColorBehavior<\/strong> behavior to\/from image. <\/li>\n<\/ul>\n\n\n\n<ul class=\"wp-block-list\">\n<li>The <strong>TintColor<\/strong> property of <strong>IconTintColorBehavior<\/strong> behavior is used for setting the color of the image.<\/li>\n<\/ul>\n\n\n\n<ul class=\"wp-block-list\">\n<li>So I am getting the selected color from color list and setting to the <strong>TintColor<\/strong> property.<\/li>\n<\/ul>\n\n\n\n<ul class=\"wp-block-list\">\n<li>We can also attach the <strong>IconTintColorBehavior<\/strong> behavior to image from xaml :<\/li>\n<\/ul>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"xml\" data-enlighter-theme=\"dracula\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\"> &lt;Image Source=\"user.png\">\n        &lt;Image.Behaviors>\n            &lt;toolkit:IconTintColorBehavior TintColor=\"Red\" \/>\n        &lt;\/Image.Behaviors>\n &lt;\/Image><\/pre>\n\n\n\n<p>We need to import <strong>toolkit<\/strong> namespace as follows :<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"xml\" data-enlighter-theme=\"dracula\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">xmlns:toolkit=\"http:\/\/schemas.microsoft.com\/dotnet\/2022\/maui\/toolkit\"<\/pre>\n\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p class=\"has-medium-font-size\"><strong>4 &#8211; Setting up the ViewModel<\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\" data-enlighter-theme=\"dracula\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">using System.Collections.ObjectModel;\nusing System.ComponentModel;\nusing System.Runtime.CompilerServices;\nusing System.Windows.Input;\n\nnamespace MAUIImageTintingSample\n{\n    public class MainPageViewModel : INotifyPropertyChanged\n    {\n        public event PropertyChangedEventHandler PropertyChanged;\n        public ICommand ColorItemClickedCommand { get; set; }\n        public ICommand ChangeImageTintColorCommand { get; set; }\n\n        private ColorItem _lastSelectedItem;\n\n        private ObservableCollection&lt;ColorItem> _colors;\n        public ObservableCollection&lt;ColorItem> Colors\n        {\n            get { return _colors; }\n            set\n            {\n                _colors = value;\n                OnPropertyChanged(nameof(Colors));\n            }\n        }\n\n        private Color _tintColor = Color.FromRgba(\"#000000\");\n        public Color Color\n        {\n            get { return _tintColor; }\n            set\n            {\n                _tintColor = value;\n                OnPropertyChanged(nameof(Color));\n            }\n        }\n\n        private bool _isAttached;\n        public bool IsAttached\n        {\n            get { return _isAttached; }\n            set\n            {\n                _isAttached = value;\n                OnPropertyChanged(nameof(IsAttached));\n            }\n        }\n\n        public MainPageViewModel()\n        {\n            ColorItemClickedCommand = new Command&lt;ColorItem>((i) => OnColorItemClicked(i));\n            ChangeImageTintColorCommand = new Command(OnChangeImageTintColor);\n            Colors = new ObservableCollection&lt;ColorItem>()\n            {\n                new ColorItem(){ Color = Color.FromArgb(\"#12AD2B\") },\n                new ColorItem(){ Color = Color.FromArgb(\"#F7DC6F\") },\n                new ColorItem(){ Color = Color.FromArgb(\"#01F9C6\") },\n                new ColorItem(){ Color = Color.FromArgb(\"#FFA500\") },\n                new ColorItem(){ Color = Color.FromArgb(\"#A2AD9C\") },\n                new ColorItem(){ Color = Color.FromArgb(\"#728FCE\") },\n                new ColorItem(){ Color = Color.FromArgb(\"#EB5406\") },\n                new ColorItem(){ Color = Color.FromArgb(\"#000000\") },\n                new ColorItem(){ Color = Color.FromArgb(\"#045D5D\") },\n            };\n        }\n        private void OnColorItemClicked(ColorItem item)\n        {\n            if (item != null)\n            {\n                if (_lastSelectedItem != null)\n                    _lastSelectedItem.IsSelected = false;\n                _lastSelectedItem = item;\n                item.IsSelected = true;\n            }\n        }\n        private void OnChangeImageTintColor()\n        {\n            if (_lastSelectedItem != null)\n            {\n                IsAttached = false;\n                Color = _lastSelectedItem.Color;\n                IsAttached = true;\n            }\n        }\n        public void OnPropertyChanged([CallerMemberName] string propertyName = null)\n        {\n            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));\n        }\n    }\n    public class ColorItem : INotifyPropertyChanged\n    {\n        private bool _isSelected;\n        public bool IsSelected\n        {\n            get { return _isSelected; }\n            set\n            {\n                _isSelected = value;\n                OnPropertyChanged();\n            }\n        }\n        private Color _color;\n        public Color Color\n        {\n            get { return _color; }\n            set\n            {\n                _color = value;\n                OnPropertyChanged();\n            }\n        }\n        public event PropertyChangedEventHandler PropertyChanged;\n        public void OnPropertyChanged([CallerMemberName] string propertyName = null)\n        {\n            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));\n        }\n    }\n}<\/pre>\n\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<ul class=\"wp-block-list\">\n<li>As in the above&nbsp;<strong>MainPageViewModel<\/strong>, I have created a list of colors and bind this to a bindable layout.<\/li>\n<\/ul>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>OnColorItemClicked()<\/strong>&nbsp;method called when a user select or pick a color from bindable layout.<\/li>\n<\/ul>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>OnChangeImageTintColor()&nbsp;<\/strong>method gets called when a user clicks on the button. This method contains the code to attach\/detach the <strong>IconTintColorBehavior<\/strong> behavior.<\/li>\n<\/ul>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p class=\"has-medium-font-size\"><strong>Result<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-video\"><video height=\"2796\" style=\"aspect-ratio: 1290 \/ 2796;\" width=\"1290\" controls src=\"https:\/\/learnmobiledevelopment.com\/wp-content\/uploads\/2023\/01\/ImageTinting.mp4\"><\/video><\/figure>\n\n\n\n<div style=\"height:40px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>That\u2019s all for now!<\/p>\n\n\n\n<p>You can check the full source code <a href=\"https:\/\/github.com\/Alam-Ashraf\/MAUIImageTintingSample.App\" target=\"_blank\" rel=\"noopener\" title=\"\">here<\/a><strong>.<\/strong><\/p>\n\n\n\n<p>Happy Coding!<strong> \ud83d\ude00<\/strong><\/p>\n\n\n\n<div style=\"height:40px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p class=\"has-medium-font-size\"><strong>You may also like<\/strong><\/p>\n\n\n\n<div class=\"wp-block-group is-content-justification-space-between is-nowrap is-layout-flex wp-container-core-group-is-layout-0dfbf163 wp-block-group-is-layout-flex\">\n<div class=\"wp-block-group is-vertical is-content-justification-center is-layout-flex wp-container-core-group-is-layout-4b2eccd6 wp-block-group-is-layout-flex\"><div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large is-resized\"><a href=\"https:\/\/learnmobiledevelopment.com\/index.php\/2022\/11\/28\/biometric-authentication-in-xamarin-forms\/\" target=\"_blank\" rel=\"noreferrer noopener\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/learnmobiledevelopment.com\/wp-content\/uploads\/2022\/11\/XamarinFormsBiometricAuthentication-1024x696.png\" alt=\"Biometric authentication in Xamarin\" class=\"wp-image-346\" width=\"512\" height=\"348\" srcset=\"https:\/\/learnmobiledevelopment.com\/wp-content\/uploads\/2022\/11\/XamarinFormsBiometricAuthentication-1024x696.png 1024w, https:\/\/learnmobiledevelopment.com\/wp-content\/uploads\/2022\/11\/XamarinFormsBiometricAuthentication-300x204.png 300w, https:\/\/learnmobiledevelopment.com\/wp-content\/uploads\/2022\/11\/XamarinFormsBiometricAuthentication-768x522.png 768w, https:\/\/learnmobiledevelopment.com\/wp-content\/uploads\/2022\/11\/XamarinFormsBiometricAuthentication-850x578.png 850w, https:\/\/learnmobiledevelopment.com\/wp-content\/uploads\/2022\/11\/XamarinFormsBiometricAuthentication.png 1236w\" sizes=\"auto, (max-width: 512px) 100vw, 512px\" \/><\/a><\/figure>\n<\/div>\n\n\n<p class=\"has-text-align-center\">Implementation Of Biometric Authentication in Xamarin Forms<\/p>\n<\/div>\n\n\n\n<p><\/p>\n\n\n\n<div class=\"wp-block-group is-vertical is-content-justification-center is-layout-flex wp-container-core-group-is-layout-4b2eccd6 wp-block-group-is-layout-flex\">\n<div class=\"wp-block-group is-vertical is-content-justification-center is-layout-flex wp-container-core-group-is-layout-4b2eccd6 wp-block-group-is-layout-flex\"><div class=\"wp-block-image is-style-default\">\n<figure class=\"aligncenter size-large is-resized\"><a href=\"https:\/\/learnmobiledevelopment.com\/index.php\/2023\/01\/02\/mediaelement-in-xamarin-forms\/\" target=\"_blank\" rel=\"noreferrer noopener\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/learnmobiledevelopment.com\/wp-content\/uploads\/2023\/01\/MediaElementInXamarin-1024x737.png\" alt=\"MediaElement in Xamarin Forms\" class=\"wp-image-631\" width=\"512\" height=\"369\" srcset=\"https:\/\/learnmobiledevelopment.com\/wp-content\/uploads\/2023\/01\/MediaElementInXamarin-1024x737.png 1024w, https:\/\/learnmobiledevelopment.com\/wp-content\/uploads\/2023\/01\/MediaElementInXamarin-300x216.png 300w, https:\/\/learnmobiledevelopment.com\/wp-content\/uploads\/2023\/01\/MediaElementInXamarin-768x553.png 768w, https:\/\/learnmobiledevelopment.com\/wp-content\/uploads\/2023\/01\/MediaElementInXamarin-850x612.png 850w, https:\/\/learnmobiledevelopment.com\/wp-content\/uploads\/2023\/01\/MediaElementInXamarin.png 1256w\" sizes=\"auto, (max-width: 512px) 100vw, 512px\" \/><\/a><\/figure>\n<\/div>\n\n\n<p class=\"has-text-align-center\">How to use MediaElement in Xamarin Forms<\/p>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Sometimes we need the same image in two different colors (eg : enable\/disable image) to show based on some conditions. So taking two images is not the right way. We need to use one image instead of two and based on some condition we need to change the color of the same image. So In&#8230;<\/p>\n","protected":false},"author":1,"featured_media":815,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[4,37],"tags":[68,65,66,67],"class_list":["post-798","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-dotnetmaui","category-maui-community-toolkit","tag-net-maui-community-toolkit","tag-apply-color-to-images","tag-apply-color-to-images-in-maui","tag-change-image-color-in-maui"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/learnmobiledevelopment.com\/index.php\/wp-json\/wp\/v2\/posts\/798","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/learnmobiledevelopment.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/learnmobiledevelopment.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/learnmobiledevelopment.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/learnmobiledevelopment.com\/index.php\/wp-json\/wp\/v2\/comments?post=798"}],"version-history":[{"count":16,"href":"https:\/\/learnmobiledevelopment.com\/index.php\/wp-json\/wp\/v2\/posts\/798\/revisions"}],"predecessor-version":[{"id":818,"href":"https:\/\/learnmobiledevelopment.com\/index.php\/wp-json\/wp\/v2\/posts\/798\/revisions\/818"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/learnmobiledevelopment.com\/index.php\/wp-json\/wp\/v2\/media\/815"}],"wp:attachment":[{"href":"https:\/\/learnmobiledevelopment.com\/index.php\/wp-json\/wp\/v2\/media?parent=798"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/learnmobiledevelopment.com\/index.php\/wp-json\/wp\/v2\/categories?post=798"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/learnmobiledevelopment.com\/index.php\/wp-json\/wp\/v2\/tags?post=798"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}