DataContext applied too late for Graphic

390
6
01-11-2011 09:57 AM
BjørnarSundsbø
Occasional Contributor
Hi

I've previously been working on a problem with dynamic centered offset for the symbol of a Graphic where the height and width of the symbol changes based on content. Post is linked to further down. I solved this using a custom IRenderer to produce a new symbol for each Graphic. I then fixed the offset of the symbol using my description from the same post (overrididing ArrangeOverride and measureOverride to calculate the offset of the symbol).

However, there is a minor problem. Whenever a new symbol is created where I use i.e. binding to an attribute to the RenderTransform (rotateTransform), I get the following binding warning
System.Windows.Data Error: 2 : Cannot find governing FrameworkElement or FrameworkContentElement for target element. BindingExpression:Path=Attributes[Bearing]; DataItem=null; target element is 'RotateTransform' (HashCode=17661557); target property is 'Angle' (type 'Double')

the binding itself works, though not on the first attempt. The same is the case if I have i.e. a GradientBrush's GradientStop bind to an attribute.

From the different suggestions I've seen for resolving this issue in other scenarios, they all suggest setting the DataContext before InitializeComponent() (in other words before applying the ControlTemplate). Is this something you could perhaps fix?

From previous attempts where I don't create a new symbol (with controltemplate) for each Graphic, the same warning is output in visual studio, though only once for each symbol where I use this kind of binding.

The following quote is a reminder of a suggestion from the post Location of PictureMarkerSymbol vs MarkerSymbol I was hoping to get some feedback on if it will be included soon or not.

I'm looking into the links you sent me. It seems this is a thing more people would be interested in, and perhaps there could be a property on the MarkerSymbol for with an enum with the following values: Manual (uses manual offset values), CenterX (centers on the X axis), CenterY (centers on the Y axis), CenterBoth (center both X and Y). Pretty much like the SizeToContent property of a Window.


Also, do you have an estimate for the next pre-release of 2.1? Or final release. I currently use the December build of 2.1.

Bjørnar Sundsbø
0 Kudos
6 Replies
JenniferNery
Esri Regular Contributor
Can you share your code for symbol ControlTemplate or the code that causes the Binding warning?
0 Kudos
BjørnarSundsbø
Occasional Contributor
Any path with the following applied to it. Add attribute Bearing to contain the value. I'll see if I can mock up a more complete sample if you can't reproduce.

                    <Path.RenderTransform>
                      <TransformGroup>
                        <RotateTransform CenterX="0.5" CenterY="0.5" Angle="{Binding Attributes[Bearing], FallbackValue=0.0}" />
                      </TransformGroup>
                    </Path.RenderTransform>
0 Kudos
JenniferNery
Esri Regular Contributor
Do you set the symbol's ControlTemplate inside GetSymbol()?

I remember the original issue when you needed to calculate the offsets based on the space occupied by the TextBlock that contains an attribute value.
0 Kudos
BjørnarSundsbø
Occasional Contributor
Do you set the symbol's ControlTemplate inside GetSymbol()?


Yes. ControlTemplate is assigned to the Symbol inside GetSymbol()
0 Kudos
dotMorten_esri
Esri Notable Contributor

From the different suggestions I've seen for resolving this issue in other scenarios, they all suggest setting the DataContext before InitializeComponent() (in other words before applying the ControlTemplate). Is this something you could perhaps fix?

This is not possible. Basically you can't guarantee that the datacontext is applied up front. The reason for that is because of some UIVirtualization going on under the covers, and UIElements being reused so the datacontext can even change to a different Graphic after the element has rendered. When the datacontext does get set, your bindings should update accordingly. The binding warning is you see is benign and only there for informational/debugging purposes. Are you saying you see a problem?


Also, do you have an estimate for the next pre-release of 2.1? Or final release. I currently use the December build of 2.1.


The december release IS the final release of v2.1. There are no public dates for v2.2 announced yet.
0 Kudos
BjørnarSundsbø
Occasional Contributor
This is not possible. Basically you can't guarantee that the datacontext is applied up front. The reason for that is because of some UIVirtualization going on under the covers, and UIElements being reused so the datacontext can even change to a different Graphic after the element has rendered. When the datacontext does get set, your bindings should update accordingly.


Do you know if there are any other workaround to get rid of the warning? A normal binding to, say a textblock, works just fine. The other scenarios mentioned do not. I suppose this is because of the timing for when the bindings are resolved, though I haven't looked into the plumbing behind this (logical tree vs visual tree?)

The strange thing is that the binding works eventually.


The december release IS the final release of v2.1. There are no public dates for v2.2 announced yet.


Ahh, I thought it was just a pre-release or something 🙂 I hope non public releases/pre-releases to 2.2 is available at the same location if I would like to try it out?

There are two bugs I'm hoping for a fix for (though I understand if you can't give an estimate for when they may be available). First is comma as the decimal separator for WmsLayer request when requesting WMS data.
The other is another post I have in the forums regarding KML layers. In addition to a few other issues I've noted in different posts, which I hope have been posted in your issue tracker. As a developer I know the time vs bug fix and feature implementation is not always in our favor :o)

Do you by any chance have an open issue tracker such as Jira where we can follow reported issues and their state? And/or perhaps report issues?
0 Kudos