WPF抛出一个元素

WPF抛出一个元素,wpf,Wpf,假设我们有一个标准的WPF应用程序,我想在我的主应用程序窗口之外的左侧显示一些UI元素 有没有一种方法可以超越窗口的边界,在我的主窗口的左侧显示一个带有按钮的视觉元素?如果有,你能给我指一个教程/视频/如何完成的提示吗?可能会弹出 简单的例子: <Window x:Class="WpfPopupTest.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://sch

假设我们有一个标准的WPF应用程序,我想在我的主应用程序窗口之外的左侧显示一些UI元素

有没有一种方法可以超越窗口的边界,在我的主窗口的左侧显示一个带有按钮的视觉元素?如果有,你能给我指一个教程/视频/如何完成的提示吗?

可能会弹出

简单的例子:

<Window x:Class="WpfPopupTest.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300">
<Grid>
    <Popup HorizontalOffset="{Binding Path=ActualWidth, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}}" IsOpen="True">
        <StackPanel Background="HotPink">
            <TextBlock Text="Hey from outside!" Foreground="Gold" />
            <Button>Button!</Button>
        </StackPanel>
    </Popup>
</Grid>

按钮


可能不知道您想做什么,但我认为它可以为您工作。

不确定您的目标是在代码或XAML中完成所有这些,但使用弹出窗口,您可以做类似的事情吗

<Window
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    x:Class="ButtonsOnPopup.MainWindow"
    x:Name="Window"
    Title="MainWindow"
    Width="400" Height="300">
<Window.Resources>
    <Storyboard x:Key="OnMouseLeftButtonDown1">
        <BooleanAnimationUsingKeyFrames BeginTime="0" Storyboard.TargetName="popup" Storyboard.TargetProperty="(Popup.IsOpen)">
            <DiscreteBooleanKeyFrame KeyTime="0" Value="True"/>
        </BooleanAnimationUsingKeyFrames>
    </Storyboard>
    <Storyboard x:Key="OnClick1">
        <BooleanAnimationUsingKeyFrames BeginTime="0" Storyboard.TargetName="popup" Storyboard.TargetProperty="(Popup.IsOpen)">
            <DiscreteBooleanKeyFrame KeyTime="0" Value="True"/>
            <DiscreteBooleanKeyFrame KeyTime="00:00:00.2" Value="False"/>
        </BooleanAnimationUsingKeyFrames>
    </Storyboard>
</Window.Resources>
<Window.Triggers>
    <EventTrigger RoutedEvent="UIElement.MouseLeftButtonDown" SourceName="textBlock">
        <BeginStoryboard Storyboard="{StaticResource OnMouseLeftButtonDown1}"/>
    </EventTrigger>
    <EventTrigger RoutedEvent="ButtonBase.Click" SourceName="button">
        <BeginStoryboard x:Name="OnClick1_BeginStoryboard" Storyboard="{StaticResource OnClick1}"/>
    </EventTrigger>
</Window.Triggers>

<Grid x:Name="LayoutRoot">
    <Popup x:Name="popup" Placement="Left">
        <StackPanel Background="White">
            <TextBlock Text="Outside Window" TextWrapping="Wrap"/>
            <Button x:Name="button" Width="75" Content="Close this"/>
        </StackPanel>
    </Popup>
    <TextBlock x:Name="textBlock" HorizontalAlignment="Center" VerticalAlignment="Center" Text="MouseDown here" TextWrapping="Wrap" Background="#FFBFFFBD"/>
</Grid>


希望这有帮助。

您可以使用无窗口边框的非模式对话框。如果你愿意,它可能会在太空中漂浮

科里