New Features in Xamarin.Forms 4.7: Multibinding, Light and Dark Modes | Syncfusion Blogs
Live Chat Icon For mobile
Live Chat Icon
Popular Categories.NET  (173).NET Core  (29).NET MAUI  (203)Angular  (107)ASP.NET  (51)ASP.NET Core  (82)ASP.NET MVC  (89)Azure  (40)Black Friday Deal  (1)Blazor  (211)BoldSign  (13)DocIO  (24)Essential JS 2  (106)Essential Studio  (200)File Formats  (65)Flutter  (132)JavaScript  (219)Microsoft  (118)PDF  (81)Python  (1)React  (98)Streamlit  (1)Succinctly series  (131)Syncfusion  (897)TypeScript  (33)Uno Platform  (3)UWP  (4)Vue  (45)Webinar  (50)Windows Forms  (61)WinUI  (68)WPF  (157)Xamarin  (161)XlsIO  (35)Other CategoriesBarcode  (5)BI  (29)Bold BI  (8)Bold Reports  (2)Build conference  (8)Business intelligence  (55)Button  (4)C#  (146)Chart  (127)Cloud  (15)Company  (443)Dashboard  (8)Data Science  (3)Data Validation  (8)DataGrid  (63)Development  (618)Doc  (8)DockingManager  (1)eBook  (99)Enterprise  (22)Entity Framework  (5)Essential Tools  (14)Excel  (39)Extensions  (22)File Manager  (6)Gantt  (18)Gauge  (12)Git  (5)Grid  (31)HTML  (13)Installer  (2)Knockout  (2)Language  (1)LINQPad  (1)Linux  (2)M-Commerce  (1)Metro Studio  (11)Mobile  (501)Mobile MVC  (9)OLAP server  (1)Open source  (1)Orubase  (12)Partners  (21)PDF viewer  (42)Performance  (12)PHP  (2)PivotGrid  (4)Predictive Analytics  (6)Report Server  (3)Reporting  (10)Reporting / Back Office  (11)Rich Text Editor  (12)Road Map  (12)Scheduler  (52)Security  (3)SfDataGrid  (9)Silverlight  (21)Sneak Peek  (31)Solution Services  (4)Spreadsheet  (11)SQL  (10)Stock Chart  (1)Surface  (4)Tablets  (5)Theme  (12)Tips and Tricks  (112)UI  (381)Uncategorized  (68)Unix  (2)User interface  (68)Visual State Manager  (2)Visual Studio  (31)Visual Studio Code  (17)Web  (582)What's new  (323)Windows 8  (19)Windows App  (2)Windows Phone  (15)Windows Phone 7  (9)WinRT  (26)
New Features in Xamarin.Forms 4.7: Multibinding, Light and Dark Modes

New Features in Xamarin.Forms 4.7: Multibinding, Light and Dark Modes

Without a doubt, the Xamarin.Forms team keeps busy developing and releasing new functions, as well as improving others. These new features allow us, as mobile application developers, to unleash all our creative skills when programming in Xamarin.Forms.

In this blog, I am going to focus on what I think are the two most important features available in the Xamarin.Forms 4.7 release. They are:

  • Multibinding
  • Light and Dark Modes

Multibinding

Multibinding describes a collection of Binding objects associated with a single binding destination property. It allows you to link a property of the binding destination to a list of source properties, and then apply logic to generate a value with the indicated entries.

Binding objects code: Source Vicente Guzman on GitHub
Source: Vicente Guzman on GitHub

Among the properties that the MultiBinding class provided us, we have Bindings, of type IList <BindingBase>, which represents the collection of Binding objects within the MultiBinding instance.

Also we have a Converter, of type IMultiValueConverter, which represents the converter that will be used to transform the values from the source to the value of the destination.

Finally, we have the ConverterParameter property, which represents an optional parameter to pass to the converter. Its type is object.

Considering these properties, and thanks to the new improvements presented in Xamarin.Forms 4.7, we can now develop applications that use MultiBinding and link a target property to a series of expressions of type BindingBase (including nested MultiBindings) to later be evaluated to a single value through an IMultiValueConverter instance that is provided by the application.

We can compose a new value—in this case a string—based on the values of different data links.

The following screenshot is a very simple example, but one that makes the functionality clear.

Multi binding: Source: Vicente Guzman GitHub
Source: Vicente Guzman GitHub

Note: It is important to consider that all the types of the secondary links must be valid MultiBindings, such as those of implicit source (BindingContext), explicit source, relative source, and even those of additional MultiBindings.

Light and Dark Modes 

The other improvement I want to discuss has been one of the most anticipated features for Xamarin.Forms: the ability to change the app style between dark and light modes. With the arrival of version 4.7, users now have even more control to manage the theme of their applications with UserAppTheme.

Light mode in Xamarin 4.7 update
Light theme in Xamarin 4.7 update

Dark mode in Xamarin 4.7 update
Dark theme in Xamarin 4.7 update

Before using this new feature, the first thing we should do is set the experimental indicator for AppTheme_Experimental, which allows us to configure the style of the application and see the real-time update of the interface at runtime, thanks to AppThemeBinding.

<Style TargetType="NavigationPage">
            <Setter Property="BarBackgroundColor"
                    Value="{AppThemeBinding Light={StaticResource LightNavigationBarColor}, Dark={StaticResource DarkNavigationBarColor}}" />
            <Setter Property="BarTextColor"
                    Value="{AppThemeBinding Light={StaticResource LightSecondaryColor}, Dark={StaticResource DarkSecondaryColor}}" />
        </Style>

Regardless of the theme that is used in the device, we can configure the theme of the application. For example, if the phone is in light mode, but we want the application we are developing to be in dark mode, we can add the following line of code:

Application.Current.UserAppTheme = OSAppTheme.Dark;

Otherwise, if we want the application theme to be kept in light mode, we use:

OSAppTheme.Light

And if we want our application to fit the device theme by default, we add this line:

OSAppTheme.Unspecified

Example:

Example: Source: Vicente Guzman GitHub
Source: Vicente Guzman GitHub

Note: It is important to mention that if AppThemeColor was used, it is necessary to update your Xamarin.Forms to Xamarin.Forms 4.7, since otherwise what was previously demonstrated in this article will not work.

 You can find examples of these new features on GitHub:

More information about these features is available at:

Conclusion

I hope you now have a clear idea about the new multibinding and dark and light mode features available with Xamarin.Forms 4.7. Try these features in your Xamarin applications and share your feedback in the comments for this blog.

Syncfusion has 150+ Xamarin UI controls and 100+ Xamarin UI templates to make developing Xamarin applications faster. You can explore Android, and UWP demo Xamarin apps; learn about our Xamarin controls’ advanced features in our documentation; and even get your hands on a 30-day free trial of all our Xamarin UI controls.

If you like this blog, we think you will also love the following resources:

Tags:

Share this post:

Popular Now

Be the first to get updates

Subscribe RSS feed

Be the first to get updates

Subscribe RSS feed