0

Why does the VisualTreeHelper.GetDescendantBounds(SomeVisualItem) method return (-Infinity,-Infinity,Infinity,Infinity)?

The SomeVisualItem's Canvas.Left, Canvas.Top, Width, ... are explicitly assigned.

Enrico Campidoglio
  • 56,676
  • 12
  • 126
  • 154
Ali Adlavaran
  • 3,697
  • 2
  • 23
  • 47
  • When do you call that? If you call that on window constructor, call it later when the visual tree is built already. eg Loaded event – nik Mar 05 '12 at 12:43
  • Yes , i know. I call that after visual tree built(for example:in some button click eventhandler) Actually,i have a rectangle in canvas that the Item is in the same canvas ,and now i want to determine that the Item is in the rectangle or not. – Ali Adlavaran Mar 05 '12 at 12:54
  • Maybe try attaching [WPF Inspector](http://wpfinspector.codeplex.com/releases/view/62380). Maybe it gives you some hint why it happens. – nik Mar 05 '12 at 13:19
  • Is SomeVisualItem a customer control ? – Dean Chalk Mar 05 '12 at 13:38
  • SomeVisualItem is a ContentControl – Ali Adlavaran Mar 05 '12 at 14:31

1 Answers1

2

I solved it. just i removed Effect from a ViewBox in my control's ControlTemplate:

<Viewbox Opacity=".7" Stretch="Uniform" IsHitTestVisible="False" FocusVisualStyle="{x:Null}" IsEnabled="False" ForceCursor="False" x:Name="PART_OutThumb">
    <Viewbox.Effect>
        <BlurEffect KernelType="Gaussian" Radius="1" />
    </Viewbox.Effect>
</Viewbox>

To:

<Viewbox Opacity=".7" Stretch="Uniform" IsHitTestVisible="False" FocusVisualStyle="{x:Null}" IsEnabled="False" ForceCursor="False" x:Name="PART_OutThumb">
</Viewbox>

Now VisualTreeHelper.GetDescendantBounds() works well!

Code Lღver
  • 15,573
  • 16
  • 56
  • 75
Ali Adlavaran
  • 3,697
  • 2
  • 23
  • 47