<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	
	>
<channel>
	<title>
	Comments on: MultiBinding in Xamarin.Forms	</title>
	<atom:link href="https://intellitect.com/blog/multibinding-in-xamarin-forms/feed/" rel="self" type="application/rss+xml" />
	<link>https://intellitect.com/blog/multibinding-in-xamarin-forms/</link>
	<description>Complex Software Development - Simplified</description>
	<lastBuildDate>Tue, 07 Mar 2023 21:25:14 +0000</lastBuildDate>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>
	<item>
		<title>
		By: Mathias Lackner		</title>
		<link>https://intellitect.com/blog/multibinding-in-xamarin-forms/#comment-359165</link>

		<dc:creator><![CDATA[Mathias Lackner]]></dc:creator>
		<pubDate>Sat, 27 Oct 2018 19:50:11 +0000</pubDate>
		<guid isPermaLink="false">http://intellitect.com/?p=23981#comment-359165</guid>

					<description><![CDATA[Hi!
This is pure magic, thank you very much for your effort.
This works great, I missed multi bindings so much in Xamarin and finally can use them! However I experienced a problem when using Converters for the binded values and want to propose a solution to it (I&#039;m using the approach with the fake assembly name &quot;Xamarin.Forms.UnitTests&quot; from your repo):

What causes the problem:
~~~~~~~~~~~~~~~~~~~~~

    
    


What is the problem:
~~~~~~~~~~~~~~~~~
If the converter is used, then the bindableObj.GetValues() in SetInternalValue will always contain old values, meaning that a change caused by the converter is not considered (SetInternalValue is invoked, but GetValues will deliver the old value). Then, the AllTrueConverter in the example above will receive wrong values (I didn&#039;t really get why, the converter ANormalConverter is invoked and returns the correct value, but AllTrueConverter receives the old value then)

How I fixed the problem for me:
~~~~~~~~~~~~~~~~~~~~~~~~~~
1) Create an extra class for providing the BindingPropertyChangedDelegate in MultiBinding.cs, which will allow us to replace the value at the matching index:
private sealed class PropertyChangedMappingProvider
{
  public PropertyChangedMappingProvider(int index, MultiBinding reference)
  {
    this.ChangedDelegate = (bindableObj, o, n) =&#062;
    {
      reference.SetInternalValue(bindableObj, index, o, n);
    };
  }
  
  public BindableProperty.BindingPropertyChangedDelegate ChangedDelegate;
}

2) Change the assignment of the BindingPropertyChangedDelegate in Method &quot;Apply&quot;:
PropertyChangedMappingProvider changedProvider = new PropertyChangedMappingProvider(i, this);
var property = BindableProperty.Create($&quot;{nameof(MultiBinding)}Property-{Guid.NewGuid():N}&quot;, typeof(object),
            typeof(MultiBinding), default(object), propertyChanged: changedProvider.ChangedDelegate);

3) Change SetInternalValue:
private void SetInternalValue(BindableObject source, int index = -1, object oldValue = null, object newValue = null)
{
  if (source == null &#124;&#124; isApplying) return;

  if (index &#062;=0 &#038;&#038; index &#060; Properties.Length)
 {
    var values = source.GetValues(Properties);
    // Be sure to override the changed property with the new value
    values[index] = newValue;
    internalValue.Value = values;
  }
  else
  {
    internalValue.Value = source.GetValues(Properties);
  }
}

I struggled a lot to find the cause and I guess this is a very, very dirty fix, though it was interesting to debug through it and see how all glues together.
Maybe you might consider to provide a more elegant solution than this in the future ;)

Warm regards,
Mathias Lackner]]></description>
			<content:encoded><![CDATA[<p>Hi!<br />
This is pure magic, thank you very much for your effort.<br />
This works great, I missed multi bindings so much in Xamarin and finally can use them! However I experienced a problem when using Converters for the binded values and want to propose a solution to it (I&#8217;m using the approach with the fake assembly name &#8220;Xamarin.Forms.UnitTests&#8221; from your repo):</p>
<p>What causes the problem:<br />
~~~~~~~~~~~~~~~~~~~~~</p>
<p>What is the problem:<br />
~~~~~~~~~~~~~~~~~<br />
If the converter is used, then the bindableObj.GetValues() in SetInternalValue will always contain old values, meaning that a change caused by the converter is not considered (SetInternalValue is invoked, but GetValues will deliver the old value). Then, the AllTrueConverter in the example above will receive wrong values (I didn&#8217;t really get why, the converter ANormalConverter is invoked and returns the correct value, but AllTrueConverter receives the old value then)</p>
<p>How I fixed the problem for me:<br />
~~~~~~~~~~~~~~~~~~~~~~~~~~<br />
1) Create an extra class for providing the BindingPropertyChangedDelegate in MultiBinding.cs, which will allow us to replace the value at the matching index:<br />
private sealed class PropertyChangedMappingProvider<br />
{<br />
  public PropertyChangedMappingProvider(int index, MultiBinding reference)<br />
  {<br />
    this.ChangedDelegate = (bindableObj, o, n) =&gt;<br />
    {<br />
      reference.SetInternalValue(bindableObj, index, o, n);<br />
    };<br />
  }</p>
<p>  public BindableProperty.BindingPropertyChangedDelegate ChangedDelegate;<br />
}</p>
<p>2) Change the assignment of the BindingPropertyChangedDelegate in Method &#8220;Apply&#8221;:<br />
PropertyChangedMappingProvider changedProvider = new PropertyChangedMappingProvider(i, this);<br />
var property = BindableProperty.Create($&#8221;{nameof(MultiBinding)}Property-{Guid.NewGuid():N}&#8221;, typeof(object),<br />
            typeof(MultiBinding), default(object), propertyChanged: changedProvider.ChangedDelegate);</p>
<p>3) Change SetInternalValue:<br />
private void SetInternalValue(BindableObject source, int index = -1, object oldValue = null, object newValue = null)<br />
{<br />
  if (source == null || isApplying) return;</p>
<p>  if (index &gt;=0 &amp;&amp; index &lt; Properties.Length)<br />
 {<br />
    var values = source.GetValues(Properties);<br />
    // Be sure to override the changed property with the new value<br />
    values[index] = newValue;<br />
    internalValue.Value = values;<br />
  }<br />
  else<br />
  {<br />
    internalValue.Value = source.GetValues(Properties);<br />
  }<br />
}</p>
<p>I struggled a lot to find the cause and I guess this is a very, very dirty fix, though it was interesting to debug through it and see how all glues together.<br />
Maybe you might consider to provide a more elegant solution than this in the future ;)</p>
<p>Warm regards,<br />
Mathias Lackner</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Kevin		</title>
		<link>https://intellitect.com/blog/multibinding-in-xamarin-forms/#comment-357607</link>

		<dc:creator><![CDATA[Kevin]]></dc:creator>
		<pubDate>Mon, 30 Apr 2018 15:18:03 +0000</pubDate>
		<guid isPermaLink="false">http://intellitect.com/?p=23981#comment-357607</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://intellitect.com/blog/multibinding-in-xamarin-forms/#comment-357538&quot;&gt;Gregory Shields&lt;/a&gt;.

Hi Gregory,

Sorry for the confusion. It sounds like you figured it out. I have updated the code in github and in this post to reflect the latest API in Xamarin.Forms 2.5.1]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://intellitect.com/blog/multibinding-in-xamarin-forms/#comment-357538">Gregory Shields</a>.</p>
<p>Hi Gregory,</p>
<p>Sorry for the confusion. It sounds like you figured it out. I have updated the code in github and in this post to reflect the latest API in Xamarin.Forms 2.5.1</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Gregory Shields		</title>
		<link>https://intellitect.com/blog/multibinding-in-xamarin-forms/#comment-357538</link>

		<dc:creator><![CDATA[Gregory Shields]]></dc:creator>
		<pubDate>Mon, 23 Apr 2018 16:23:00 +0000</pubDate>
		<guid isPermaLink="false">http://intellitect.com/?p=23981#comment-357538</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://intellitect.com/blog/multibinding-in-xamarin-forms/#comment-357524&quot;&gt;Gregory Shields&lt;/a&gt;.

Well, I finally realized that an additional optional parameter was added to the Apply and Unapply methods.
It works now after adding those!]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://intellitect.com/blog/multibinding-in-xamarin-forms/#comment-357524">Gregory Shields</a>.</p>
<p>Well, I finally realized that an additional optional parameter was added to the Apply and Unapply methods.<br />
It works now after adding those!</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Gregory Shields		</title>
		<link>https://intellitect.com/blog/multibinding-in-xamarin-forms/#comment-357533</link>

		<dc:creator><![CDATA[Gregory Shields]]></dc:creator>
		<pubDate>Mon, 23 Apr 2018 11:57:56 +0000</pubDate>
		<guid isPermaLink="false">http://intellitect.com/?p=23981#comment-357533</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://intellitect.com/blog/multibinding-in-xamarin-forms/#comment-357524&quot;&gt;Gregory Shields&lt;/a&gt;.

So I just now reverted back to Xamarin.Forms 2.5.0.280555 and the project compiles just fine once again. I&#039;m perplexed.]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://intellitect.com/blog/multibinding-in-xamarin-forms/#comment-357524">Gregory Shields</a>.</p>
<p>So I just now reverted back to Xamarin.Forms 2.5.0.280555 and the project compiles just fine once again. I&#8217;m perplexed.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Gregory Shields		</title>
		<link>https://intellitect.com/blog/multibinding-in-xamarin-forms/#comment-357525</link>

		<dc:creator><![CDATA[Gregory Shields]]></dc:creator>
		<pubDate>Sun, 22 Apr 2018 19:42:05 +0000</pubDate>
		<guid isPermaLink="false">http://intellitect.com/?p=23981#comment-357525</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://intellitect.com/blog/multibinding-in-xamarin-forms/#comment-357524&quot;&gt;Gregory Shields&lt;/a&gt;.

Although in browsing the source online, it appears to still be there. If that be the case, I&#039;m not quite sure why upgrading to the latest Xamarin.Forms would cause the project to fail compilation.]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://intellitect.com/blog/multibinding-in-xamarin-forms/#comment-357524">Gregory Shields</a>.</p>
<p>Although in browsing the source online, it appears to still be there. If that be the case, I&#8217;m not quite sure why upgrading to the latest Xamarin.Forms would cause the project to fail compilation.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Gregory Shields		</title>
		<link>https://intellitect.com/blog/multibinding-in-xamarin-forms/#comment-357524</link>

		<dc:creator><![CDATA[Gregory Shields]]></dc:creator>
		<pubDate>Sun, 22 Apr 2018 19:27:17 +0000</pubDate>
		<guid isPermaLink="false">http://intellitect.com/?p=23981#comment-357524</guid>

					<description><![CDATA[After updating to Xamarin.Forms 2.5.1.444934 I can no longer build this project. I&#039;m assuming that the InternalsVisibleTo attribute has been removed for the unit testing assembly.]]></description>
			<content:encoded><![CDATA[<p>After updating to Xamarin.Forms 2.5.1.444934 I can no longer build this project. I&#8217;m assuming that the InternalsVisibleTo attribute has been removed for the unit testing assembly.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Kevin		</title>
		<link>https://intellitect.com/blog/multibinding-in-xamarin-forms/#comment-355133</link>

		<dc:creator><![CDATA[Kevin]]></dc:creator>
		<pubDate>Sun, 17 Sep 2017 19:44:05 +0000</pubDate>
		<guid isPermaLink="false">http://intellitect.com/?p=23981#comment-355133</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://intellitect.com/blog/multibinding-in-xamarin-forms/#comment-355132&quot;&gt;Ady Shimony&lt;/a&gt;.

Thank you for your comment. The GitHub repository has been updated to the latest Xaramin.Forms nuget (v2.3.4.270). If you are still seeing compile issues please open an issue on the GitHub repository. https://github.com/Keboo/Xamarin.Forms.Proxy]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://intellitect.com/blog/multibinding-in-xamarin-forms/#comment-355132">Ady Shimony</a>.</p>
<p>Thank you for your comment. The GitHub repository has been updated to the latest Xaramin.Forms nuget (v2.3.4.270). If you are still seeing compile issues please open an issue on the GitHub repository. <a href="https://github.com/Keboo/Xamarin.Forms.Proxy" rel="nofollow ugc">https://github.com/Keboo/Xamarin.Forms.Proxy</a></p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Ady Shimony		</title>
		<link>https://intellitect.com/blog/multibinding-in-xamarin-forms/#comment-355132</link>

		<dc:creator><![CDATA[Ady Shimony]]></dc:creator>
		<pubDate>Sun, 17 Sep 2017 14:20:43 +0000</pubDate>
		<guid isPermaLink="false">http://intellitect.com/?p=23981#comment-355132</guid>

					<description><![CDATA[This is not compiling anymore.]]></description>
			<content:encoded><![CDATA[<p>This is not compiling anymore.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Burt		</title>
		<link>https://intellitect.com/blog/multibinding-in-xamarin-forms/#comment-336231</link>

		<dc:creator><![CDATA[Burt]]></dc:creator>
		<pubDate>Thu, 02 Mar 2017 17:47:05 +0000</pubDate>
		<guid isPermaLink="false">http://intellitect.com/?p=23981#comment-336231</guid>

					<description><![CDATA[Hi Kevin,

Thanks for your work and explanation. 

I got your simpler version of MultiBinding.cs working. (https://gist.github.com/Keboo/0d6e42028ea9e4256715)
For the moment that will do for me.

In the future I might get back on this topic and study the rest.]]></description>
			<content:encoded><![CDATA[<p>Hi Kevin,</p>
<p>Thanks for your work and explanation. </p>
<p>I got your simpler version of MultiBinding.cs working. (<a href="https://gist.github.com/Keboo/0d6e42028ea9e4256715" rel="nofollow ugc">https://gist.github.com/Keboo/0d6e42028ea9e4256715</a>)<br />
For the moment that will do for me.</p>
<p>In the future I might get back on this topic and study the rest.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Kevin		</title>
		<link>https://intellitect.com/blog/multibinding-in-xamarin-forms/#comment-312021</link>

		<dc:creator><![CDATA[Kevin]]></dc:creator>
		<pubDate>Wed, 14 Sep 2016 15:29:16 +0000</pubDate>
		<guid isPermaLink="false">http://intellitect.com/?p=23981#comment-312021</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://intellitect.com/blog/multibinding-in-xamarin-forms/#comment-312011&quot;&gt;Jim Tyminski&lt;/a&gt;.

Hi Jim,

The converter is a very simple class that simply grabs the first value that is not null. Here is the complete code for it:

using System;
using System.Globalization;
using System.Linq;
using Xamarin.Forms.Proxy;

namespace MultiBindingExample
{
    public class FirstNotNullConverter : IMultiValueConverter
    {
        public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
        {
            return values.FirstOrDefault(x =&gt; x != null) ?? parameter;
        }
    }
}]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://intellitect.com/blog/multibinding-in-xamarin-forms/#comment-312011">Jim Tyminski</a>.</p>
<p>Hi Jim,</p>
<p>The converter is a very simple class that simply grabs the first value that is not null. Here is the complete code for it:</p>
<p>using System;<br />
using System.Globalization;<br />
using System.Linq;<br />
using Xamarin.Forms.Proxy;</p>
<p>namespace MultiBindingExample<br />
{<br />
    public class FirstNotNullConverter : IMultiValueConverter<br />
    {<br />
        public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)<br />
        {<br />
            return values.FirstOrDefault(x => x != null) ?? parameter;<br />
        }<br />
    }<br />
}</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Jim Tyminski		</title>
		<link>https://intellitect.com/blog/multibinding-in-xamarin-forms/#comment-312011</link>

		<dc:creator><![CDATA[Jim Tyminski]]></dc:creator>
		<pubDate>Wed, 14 Sep 2016 14:27:43 +0000</pubDate>
		<guid isPermaLink="false">http://intellitect.com/?p=23981#comment-312011</guid>

					<description><![CDATA[Hi Kevin,  Love the work on this one!  But I can&#039;t figure out where FirstNotNullConverter is defined?  I am getting

Additional information: Position 22:8. Type helper:FirstNotNullConverter not found in xmlns clr-namespace:Ximon.Helpers;assembly=Ximon

Yes, I checked my namespace and it is OK.  

I copied the code directly from GitHub (I used the NON-SETTER version)

And My XAML:


    
      
    
  

....


                
                  
                    
                      
                      
                      
                    
                  
                

Any ideas?  Thanks!!!]]></description>
			<content:encoded><![CDATA[<p>Hi Kevin,  Love the work on this one!  But I can&#8217;t figure out where FirstNotNullConverter is defined?  I am getting</p>
<p>Additional information: Position 22:8. Type helper:FirstNotNullConverter not found in xmlns clr-namespace:Ximon.Helpers;assembly=Ximon</p>
<p>Yes, I checked my namespace and it is OK.  </p>
<p>I copied the code directly from GitHub (I used the NON-SETTER version)</p>
<p>And My XAML:</p>
<p>&#8230;.</p>
<p>Any ideas?  Thanks!!!</p>
]]></content:encoded>
		
			</item>
	</channel>
</rss>
