zvrastil
zvrastil

Reputation: 1

Create shadow in WPF without using effect

the problem is following: we have an application that shows live image within a control called Display. There can be (potentially interactive) layers on top of the live image within the Display control (Display control is basically a Grid with LiveImageLayer at the bottom). Most available layers consist of line graphics to not obsure the image. Some layers are composed of standard WPF controls like buttons or sliders (with altered template so they're rendered using line graphics). Some layers are even drawn directly using DrawingContext.

To improve visibility and readability of the layer graphics on top of live noisy image, we tried to assing DropShadow effect to the layers. This worked very well from visual point-of-view. However, it was very bad from performance point-of-view. Due to fast update of ImageLayer (up to 60Hz), DropShadow effects got recalculated for all layers with the image update frequency (even if layers themselves do not change).

We can implement old-fashioned shadow (same graphics with black pen-and-brush below, shifted to the lower right) manually for each layer. And we'll actually do it if there's no better way.

So, my question is: is there any automatic or semi-automatic way to achieve such shadow? I thought of creating shifted rectangle below the actual layer, which brush set to visual brush of the actual layer. However, I found no way (other than Effect) to re-color the visual brush to black.

Any ideas?

Upvotes: 0

Views: 1263

Answers (1)

sa_ddam213
sa_ddam213

Reputation: 43626

I had similar performance issues with shodows a while back, I ended up just using Border to make a fake shadow, However in my Usercontrols I used a LinearGradientBrush that made the shadow a bit more realistic but I can't remember the brush settings, But this is kind of the effect it created.

enter image description here

<Grid>
     <Border Margin="57,74,162,114" BorderThickness="2,0,0,2" CornerRadius="5" BorderBrush="#AA000000">
            <Button Content="StackOverflow" />
    </Border>
</Grid>

Its a bit of a bummer that WPF Effects are CPU rendered as shadows to solve issues like your describing.

Upvotes: 1

Related Questions