Silverlight Custom effect, get parent

202 Views Asked by At

I am trying to create a custom effect by inheriting from Effect.

<Ellipse Width="75" Height="75" Stroke="LightGray">
    <Ellipse.Effect>
        <local:GlowEffect GlowRadius="10"/>
    </Ellipse.Effect>
</Ellipse>

The problem is in my effect code. I have no way of getting the parent of the effect property, in this case, that ellipse. You cannot use VisualTreeHelper as the ellipse will not have been loaded in the visual tree when the GlowEffect is constructed (in its constructor). I have not found a way to get by this issue, or maybe I'm just going about this the wrong way.

1

There are 1 best solutions below

1
On

All "Magic" is implemented in shader file (.fx extension), but not in C# Effect class. You have access to all pixels and their colors in shader, and you can combine colors of neighbour pixels as you wish.

sampler2D input : register(S0);
float4 main(float2 uv : TEXCOORD) : COLOR
{
   // access to current pixel
   float4 color1 = tex2D(input, uv);

   // access to neighbour pixel
   float2 offset = (some value);
   float4 color2 = tex2D(input, uv + offset);

   return (any formula based on color1 and color2);
}

I recommend you to read this book if you plan to create custom effects.

And answer to your question is - you not need to get access to Parent element.