Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how can prevent popup close when mouse clicked outsie of popop

Tags:

c#

wpf

In WPF When we clicked on Toggle button then popup open properly but when we clicked on outside of popup then popup is auto closed. how to prevent this.

when we clicked on outside of popup then the popup should not be closed.

Code:

<ToggleButton Name="TglBtn" Content="Document" /> 
<Popup IsOpen="{Binding IsChecked, ElementName=TglBtn}" StaysOpen="False"   PlacementTarget="{Binding ElementName=popupDocshow}" x:Name="pop1"> 
  <TextBlock Text="Documents" Background="Blue"/> 
</Popup>
like image 302
Neeta Paliwal Avatar asked Nov 20 '25 02:11

Neeta Paliwal


1 Answers

PopupTest.StaysOpen = true this is what you are missing.

<Popup x:Name="PopupTest" AllowsTransparency="True">
    <Viewbox VerticalAlignment="Top">
        <TextBlock Text="Wow, that was easy!"/>
    </Viewbox>
</Popup>

private void Button_Click(object sender, RoutedEventArgs e)
{
    PopupTest.Placement = System.Windows.Controls.Primitives.PlacementMode.Mouse;
    PopupTest.StaysOpen = true;
    PopupTest.Height = 1000;
    PopupTest.Width = 500;
    PopupTest.IsOpen = true;       
}

this is the popup i checked on

like image 115
Avinash Reddy Avatar answered Nov 21 '25 16:11

Avinash Reddy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!