Question

Is there a way to manipulate to order in which Dependency Properties receive their values :

XAML :

         <Window   local:MyHelper.SomeAttachedProp="{Binding Something , Mode=OneWay}">
              <Grid>
                  <TextBlock Text="Let him go first" 
                             local:MyHelper.AnotherAttachedBooleanProp="True" />
              </Grid>
         </Window>

CS :

         public static class MyHelper 
         {
             propa .... 

             OnSomeAttachedPropChanged( .... )
             {
                 // I WANT TO GET HERE FIRST
             }

             propa ..... 

             OnAnotherAttachedBooleanPropChanged( .... )
             { 
                 // I WANT TO GET HERE SECOND 
             }                    
         }

Currently i'm reaching AnotherAttachedBooleanPropChanged before OnSomeAttachedPropChanged is there any way to control to order in which Dependency Properties are updated ?

Edit :

I just remembered/realized something , the DP with a direct assignment will get updated before the bound one .

No correct solution

OTHER TIPS

I don't know of any direct way to do that. And i personally never had the desire to do so. When you only use the OnXYZChanged methods to register to events (which is imo the most common case) you could register to an event which better suits the order of your desired code execution. For example, in the OnXYZChanged register to Loaded event and handle that, the order of these should be afair from Root to child, and therefore in the correct order.

Another way would be to test which one was called second, and do your logic in there. Another idea would be to use the Dispatcher and do all the logic at a later time where its sure that everything is loaded.

And a final idea, You could traverse with the VisualTreeHelper from the child element in the OnXYZChanged to the underlying window and set the property on the window first and then handle the logic for the child.

@Your edit:

If you think about it, it makes sense. The visual tree must be created and everything must be chained before the Binding can traverse the tree to find the appropiate DataContext.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top