Miro
Miro

Reputation: 135

C# WPF draw control outside its container

I have problem with drop shadow performance so I decided replace drop shadow with rectangle. Looks good, but problem is rectangle is not drawed over own container.

            <!-- Window -->
            <Viewbox x:Name="viewboxDC">

                <Grid>

                    <!-- Shadow -->
                    <Rectangle Panel.ZIndex="-1"  Margin="0,0,-12,-12" Width="1282" Height="722" Fill="#7F000000" />

                    <Border x:Name="BorderWindowSize" BorderBrush="Black" BorderThickness="1"  Background="White" Width="1282" Height="722">

                        <Canvas Panel.ZIndex="1" x:Name="DesignCanvas" Background="White" MouseDown="DesignCanvas_MouseDown" >
                        </Canvas>

                    </Border>
                </Grid>
            </Viewbox>

I get this: Current status

I want:enter image description here

Is there anything to ignore container size? Or fast alternative to dropshadow effect? Thanks.

Upvotes: 0

Views: 1004

Answers (1)

Cogeck
Cogeck

Reputation: 86

Try to put a Canvas around:

Got the same problem:

<Canvas x:Name="ClipCanvas" Grid.Row="0">

                <Viewbox x:Name="Pin" RenderTransformOrigin=".5,1" Height="72" Margin="6,-72,0,0" 
                         Visibility="Collapsed">

                    <Grid>

                        <Path
                            Data="blubb"
                            Fill="{DynamicResource PrimaryBrush}"
                            Grid.Row="0" Margin="-7,2,-8,4" />

                        <TextBlock x:Name="FormattedValue"
                                   Text="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type vw:Slider}}, Path=FormattedValue}"
                                   Foreground="{DynamicResource PrimaryForegroundBrush}"
                                   HorizontalAlignment="Center" VerticalAlignment="Center"
                                   FontWeight="Normal" FontSize="11"
                                   Margin="-7 -6 -7 0" />

                    </Grid>

                    <Viewbox.RenderTransform>
                        <TransformGroup>
                            <ScaleTransform ScaleX="0" ScaleY="0" />
                            <TranslateTransform Y="4" />
                        </TransformGroup>
                    </Viewbox.RenderTransform>

                </Viewbox>

            </Canvas>

I wanted to draw outside the Viewbox. This solved my problem.

Upvotes: 3

Related Questions