-->

Displaying wpf content over/outside main window bo

2020-04-05 07:24发布

问题:


Want to improve this question? Update the question so it's on-topic for Stack Overflow.

Closed 5 years ago.

I am trying to achieve an effect of overlapping the main window boundary with a control. It's hard to explain this in words which is also maybe why I am having difficulty finding information on how to do this or if it is even possible.

Below is an example of the effect I am trying to get (from the designer), where the "note" objects float outside the bounds of the main window.

However the effect I get at runtime is this (below), the inner controls are clipped by the boundary of the main window.

Can someone please tell me if this is possible (or not), and if it is maybe some suggestions about how I could get this effect.

回答1:

I don't think there's a way to draw outside the bounds of a window. However, you could simply create a new window for the note control and align it to your main window.



回答2:

There is a control that can achieve this kind a behavior have you tried a Popup control? Check this out

Here's an examp;e"

<Window x:Class="MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow" Height="350" Width="525">
<Grid>
    <ToggleButton x:Name="MainButton" Content="Show popup" VerticalAlignment="Top" HorizontalAlignment="Right"/>
    <Popup PlacementTarget="{Binding ElementName=MainButton}" Placement="Bottom" AllowsTransparency="True" IsOpen="{Binding ElementName=MainButton, Path=IsChecked}">
        <Grid>
            <Border BorderBrush="Orange" BorderThickness="1" Background="Yellow"/>
            <TextBlock Text="Lorem Ipsum is simply dummy text of the printing and typesetting industry"/>
        </Grid>            
    </Popup>
</Grid>



回答3:

Contents of window will always get clipped. So basically there is only one way to go here. You could get the desired effect by creating a new transparent window for your floating content and then manualy set and update the position of floating content window based on the location of main window.

So far I've been using AvalonDock for similar functionalty. You might give it a try...



回答4:

Did you try ClipToBounds property?