1
我有簡單的邊框控制,MouseEnter
事件打開彈出控件。彈出窗口比邊界更大,因此它超出了邊界的範圍。彈出窗口也有一些按鈕和文本塊,所以我需要對它進行一些控制。現在,我想要獲得的東西:鼠標進入邊框 - 彈出窗口出現。鼠標離開邊框並彈出 - 彈出關閉。所以,當鼠標不在邊框上方,而是在彈出框上時,彈出窗口保持打開狀態。我不想關閉點擊。你可以幫我嗎? WPF中的Popup控件令我感到困惑。WPF彈出式菜單 - 隱藏只有鼠標離開控件和彈出框
編輯: 權,代碼:
<Window x:Class="Sandbox.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:Sandbox"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525">
<Grid Margin="20">
<Popup PopupAnimation="Fade" Placement="Top" PlacementTarget="{Binding ElementName=OpenPopupBorder}" AllowsTransparency="True" StaysOpen="True" x:Name="DeviceStatusSnippetPopup">
<Border Background="White" Padding="5" BorderBrush="Black" BorderThickness="1">
<Grid>
<StackPanel Orientation="Vertical">
<TextBlock HorizontalAlignment="Center" Text="Device status snippet" Margin="0 10 0 10"/>
<StackPanel Orientation="Horizontal">
<Button Style="{StaticResource btn-default}" Margin="0 0 5 0" Content="Go to device"/>
<Button Style="{StaticResource btn-default}" Content="Refresh device"/>
</StackPanel>
</StackPanel>
</Grid>
</Border>
</Popup>
<Border x:Name="OpenPopupBorder" Width="90" Height="30" Background="LightGray" MouseEnter="Border_MouseEnter"/>
</Grid>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void Border_MouseEnter(object sender, MouseEventArgs e)
{
DeviceStatusSnippetPopup.IsOpen = true;
}
}
你會在這裏分享你的一些代碼嗎? – MikkaRin
只需爲'IsMouseOver'屬性的'popup'設置觸發器,如果IsMouseOver == true,那麼在setter' popup.IsOpen = true'中,然後設置'IsMouseOver == false' =>'popup.IsOpen = false' 。它非常簡單。 – Shakra