c# wpf popup label

c# - ¿Cómo hacer que una ventana emergente permanezca abierta cuando aparece el mouseover en WPF?



popup label (1)

Estoy haciendo una aplicación WPF donde tengo una etiqueta. Cuando aparezca el disparador de etiqueta en la ventana emergente con el mouseover. En esta ventana emergente tengo algunos botones con diferentes acciones. Pero cuando toco la etiqueta, aparece la ventana emergente pero no puedo usar mi ventana emergente antes de que desaparezca al activar mouseleave.

Aquí está mi código XAML:

<Label x:Name="userLabel" Content="Label" Grid.Column="2" HorizontalAlignment="Left" Margin="404,31,0,0" VerticalAlignment="Top" Width="145" Foreground="White" MouseEnter="UserLabelMouseEnter" MouseLeave="UserLabelMouseLeave"/> <Popup Name="UserMenuPopUp" PopupAnimation="Fade" Height="auto" Margin="0,0,0,0" AllowsTransparency="True" Placement="bottom" PlacementTarget="{Binding ElementName=userLabel}" StaysOpen="false"> <Border BorderThickness="1" Background="#EEEEEE" Height="160" HorizontalAlignment="Left" Width="195" RenderTransformOrigin="0.5,0.5"> <Grid> <Button x:Name="profile" Content="profile" Margin="0,0,0,0" VerticalAlignment="Top" Height="40" BorderThickness="0" Click="ProfileBtn_Click" Foreground="White" HorizontalContentAlignment="Right"> <Button.Style> <Style TargetType="{x:Type Button}"> <Setter Property="Background" Value="#282828"/> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type Button}"> <Border Background="{TemplateBinding Background}"> <ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/> </Border> </ControlTemplate> </Setter.Value> </Setter> <Style.Triggers> <Trigger Property="IsMouseOver" Value="True"> <Setter Property="Background" Value="#79B539"/> </Trigger> </Style.Triggers> </Style> </Button.Style> </Button> <Button x:Name="RentalPlans" Content="Rental plans" Margin="0,40,0,0" VerticalAlignment="Top" Height="40" BorderThickness="0" Click="RentalPlansBtn_Click" Foreground="White"> <Button.Style> <Style TargetType="{x:Type Button}"> <Setter Property="Background" Value="#282828"/> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type Button}"> <Border Background="{TemplateBinding Background}"> <ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/> </Border> </ControlTemplate> </Setter.Value> </Setter> <Style.Triggers> <Trigger Property="IsMouseOver" Value="True"> <Setter Property="Background" Value="#79B539"/> </Trigger> </Style.Triggers> </Style> </Button.Style> </Button> <Button x:Name="MyCredits" Content="My credit cards" Margin="0,80,0,0" VerticalAlignment="Top" Height="40" BorderThickness="0" Click="MycreditsBtn_Click" Foreground="White"> <Button.Style> <Style TargetType="{x:Type Button}"> <Setter Property="Background" Value="#282828"/> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type Button}"> <Border Background="{TemplateBinding Background}"> <ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/> </Border> </ControlTemplate> </Setter.Value> </Setter> <Style.Triggers> <Trigger Property="IsMouseOver" Value="True"> <Setter Property="Background" Value="#79B539"/> </Trigger> </Style.Triggers> </Style> </Button.Style> </Button> <Button x:Name="LogOut" Content="Log out" Margin="0,120,0,0" VerticalAlignment="Top" Height="40" BorderThickness="0" Foreground="White" Click="LogOuBtn_Click"> <Button.Style> <Style TargetType="{x:Type Button}"> <Setter Property="Background" Value="#282828"/> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type Button}"> <Border Background="{TemplateBinding Background}"> <ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/> </Border> </ControlTemplate> </Setter.Value> </Setter> <Style.Triggers> <Trigger Property="IsMouseOver" Value="True"> <Setter Property="Background" Value="#79B539"/> </Trigger> </Style.Triggers> </Style> </Button.Style> </Button> </Grid> </Border> </Popup>

Aquí está mi código de C #:

private void UserLabelMouseEnter(object sender, MouseEventArgs e) { UserMenuPopUp.IsOpen = true; } private void UserLabelMouseLeave(object sender, MouseEventArgs e) { UserMenuPopUp.IsOpen = false; }


Puede mover el código MouseLeave evento MouseLeave de Popup.