Bindings are executed twice
See original GitHub issueDescription
It appears that XAML bindings are being executed twice in certain circumstances. I’ve got several different situations in my MAUI application where this appears to be happening. At the moment I can only reproduce the following in a greatly simplified situation.
If I place a binding at the top of a Page definition, all the bindings on that page will we executed 2 times. It also appears that any IValueConverter attached to the binding is executed AFTER the lower bindings are applied the 1st time.
Thus if we have the following code:
<?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"
xmlns:converters="clr-namespace:MauiBugz.Converters"
xmlns:views="clr-namespace:MauiBugz.Views"
BindingContext="{Binding Property, Mode=OneTime, Converter={x:Static converters:CountingConverter.Instance}, ConverterParameter='TopOfPage'}"
x:Class="MauiBugz.Views.IssueView"
Title="IssueView">
<VerticalStackLayout>
<ContentView
BindingContext="{Binding Property, Mode=OneTime, Converter={x:Static converters:CountingConverter.Instance}, ConverterParameter='OneLevelDown'}"/>
<ContentView
BindingContext="{Binding Property, Mode=OneTime, Converter={x:Static converters:CountingConverter.Instance}, ConverterParameter='CustomContent'}"/>
</VerticalStackLayout>
</ContentPage>
We will see the following progression:
[DOTNET] IssueViewModel Get Property
[DOTNET] OneLevelDown converter has been executed 1 times. Value: Data_A
[DOTNET] IssueViewModel Get Property
[DOTNET] CustomContent converter has been executed 1 times. Value: Data_A
[DOTNET] IssueViewModel Get Property
[DOTNET] TopOfPage converter has been executed 1 times. Value: Data_A <<<<<<<<<<<<<<
[DOTNET] ConvertedData_A Get Property
[DOTNET] OneLevelDown converter has been executed 2 times. Value: Data_B
[DOTNET] ConvertedData_A Get Property
[DOTNET] CustomContent converter has been executed 2 times. Value: Data_B
Note that TopOfPage converter is executed after all the lower bindings have been presented with the VM applied to the page. They were never to see the VM, they were to receive ConvertedData objects that were derived from the Data object returned from the VM.Property getter. (As you see in the 2nd half of the console output.)
Steps to Reproduce
- Clone the Repro
- Select the button for the Issue
- View the Console output.
NOTE: This issue is a bit tedious to illustrate via output as Bindings are relatively verbose processes with several steps. I’ve implemented the following in an attempt to help track the issue via console output.
CountingConverter is an IValueConverter implementation with the following:
- Static
Instanceproperty that returns a unique/new converter for each access. (Each binding has it’s own instance) ConverterParameteris expected to be a string “name” to uniquely identify each converter.- Designed to count each time it’s executed and prints it’s name, the count, and the value and it’s provided to the Console.
- Takes a
Dataobject in, and returns aConvertedDataobject.
The initial ViewModel, Data, and ConvertedData all share the same Property property to simplify coding down the XAML tree.
- The getter creates a new
Dataobject on first access.
Data and ConvertedData get a new designation character when they are created to make each unique.
Link to public reproduction project repository
https://github.com/bakerhillpins/Issues/tree/NetMauiIssue10806
Version with bug
6.0.486 (current)
Last version that worked well
Unknown/Other
Affected platforms
iOS, Android, Windows, macOS
Affected platform versions
All
Did you find any workaround?
It appears that if you insert ContentView between your actual XAML and the Page (effectively wrapping your view) and move the TopOfPage binding down to that wrapper ContentView, the bindings are only executed once.
The Caveat here is that I’m actually using this workaround in my larger application, however, I’m still seeing the issue and have not been able to determine why at the moment.
Relevant log output
No response
Issue Analytics
- State:
- Created a year ago
- Comments:7

Top Related StackOverflow Question
We’ve moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.
I’ve added a fix for this to the PR above, https://github.com/dotnet/maui/pull/12060