0

I got the code below, in which I'm interested to know whether the second binding (of the second condition of the trigger) has its binding object created when the TreeViewItem is loaded? or only if the first condition was True?

<Style TargetType="TreeViewItem">
           <Style.Triggers>
                <MultiDataTrigger>
                    <MultiDataTrigger.Conditions>
                        <Condition Binding="{Binding RelativeSource={RelativeSource Self}, Path=IsMouseOver}"
                                   Value="True"/>
                        <Condition Binding="{Binding RelativeSource={RelativeSource FindAncestor,AncestorType=TreeView}, Path=DataContext.IsConfigurationAttributeEnabled}"
                                   Value="True"/>
                    </MultiDataTrigger.Conditions>
                   <Setter Property="Foreground"
                           Value="Aqua"/>
               </MultiDataTrigger>
           </Style.Triggers>
       </Style>

Let's guess we have a DataGrid and each cell has something like 5 MultiDataTriggers with 4 conditions in each one of it. The most of the multi data triggers will fail at the first condition (bounded to some system property with Mode=OneTime). In such case I think it's a bit heavy that each cell creates so much bindings objects in vain. Or maybe it's not that critical because we have virtualization and paging?

Yanko Pata
  • 175
  • 1
  • 10
  • This should answer your question: https://stackoverflow.com/a/19889144/109702 – slugster Feb 07 '18 at 18:43
  • Nope. I've asked whether WPF is creating the bindings objects of the second and the third condition (not trigger) even though the first condition failed and they never got reached. In other words, whether all the bindings objects for the conditions are created on window loading, or only if the previous condition was met. The memory side got me interested here. – Yanko Pata Feb 07 '18 at 21:23

1 Answers1

1

I got the code below, in which I'm interested to know whether the second binding (of the second condition of the trigger) has its binding object created when the TreeViewItem is loaded?

Yes. The binding is created as soon as the Style is applied to a TreeViewItem.

or only if the first condition was True?

No.

In such case I think it's a bit heavy that each cell creates so much bindings objects in vain.

Well, heavy or not, that's what it does. This shouldn't be an issue in general though. A Binding object is pretty small and the garbage collector will eventually collect any ones that are no longer in used by your application.

mm8
  • 163,881
  • 10
  • 57
  • 88