Note that there are some explanatory texts on larger screens.

plurals
  1. POSet Binding as other Binding's Source
    text
    copied!<p>I have a <code>TabControl</code>, and I want to do the following:</p> <ol> <li>Take first and last of the <code>TabItem</code>s in <code>TabControl.Items</code></li> <li>Get their <code>Margin</code>s</li> <li>Supply those <code>Thickness</code>es to the converter to convert these two structs into final value</li> </ol> <p>Here is a related code showing what I am trying to do:</p> <pre><code>&lt;Border.Padding&gt; &lt;MultiBinding Converter="{StaticResource MarginsToPaddingConverter}"&gt; &lt;Binding Path="Margin"&gt; &lt;Binding.Source&gt; &lt;Binding RelativeSource="{RelativeSource AncestorType=TabControl}" Path="Items" Converter="{StaticResource ItemCollectionToFirstItemConverter}" ConverterParameter="{x:Type TabItem}" /&gt; &lt;/Binding.Source&gt; &lt;/Binding&gt; &lt;Binding Path="Margin"&gt; &lt;Binding.Source&gt; &lt;Binding RelativeSource="{RelativeSource AncestorType=TabControl}" Path="Items" Converter="{StaticResource ItemCollectionToLastItemConverter}" ConverterParameter="{x:Type TabItem}" /&gt; &lt;/Binding.Source&gt; &lt;/Binding&gt; &lt;/MultiBinding&gt; &lt;/Border.Padding&gt; </code></pre> <p>But I can't set <code>Binding</code> as <code>RelativeSource</code> or <code>Source</code> of other <code>Binding</code>. Basically the solution at hand is to create converter, which would take <code>TabControl.Items</code> and convert it to the final value, but the problem is I want to animate <code>Margin</code>s of both <code>TabItem</code>s, so I need to bind specifically to these properties. If I would bind to <code>TabControl.Items</code>, the <code>Border.Padding</code> would not get refreshed if <code>Margin</code> of any <code>TabItem</code> would change. So what should I do?</p> <h2>Update</h2> <p>Ok, so one of the possible solutions is to hook into <code>TabItem.Loaded</code> event, and then use <code>DependencyPropertyDescriptor</code> to hook <code>Changed</code> event on appropriate properties, then hook all items in <code>TabItem.Items</code> collection, hook any new items and automatically unhook all old items, and hook like million other stuff. But this is quite complicated and it's like 400 LOC. Isn't there anything simpler? Preferably in pure <code>XAML</code>.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload