Handling Popup with Togglebutton RRS feed

  • Question

  • I have a Toggle button and a popup in Xaml. popup's IsOpen bound to toggle button's IsChecked and the Popup's StaysOpen is set to false. So the popup will get open when the toggle button checked and close if unchecked. This works fine.

    My problem is i have opened the popup and click away from popup, this close my popup due to its stays open false and if i tried to open the popup by clicking the toggle button, popup not get open. Since it is in checked state, and its turn into unchecked state. so its not open the popup.

    Any idea, How may i handle this?


    Friday, May 10, 2013 4:39 AM


All replies

  • Have you considered a different control altogether?

    Maybe just a grid or any sort of panel which opens on top of most of the UI and you collapse it.

    Friday, May 10, 2013 7:02 AM
  • Hello Sankar.

    Have you tried setting your IsOpen binding of the Popup to TwoWay and use the UpdateSourceTrigger=PropertyChanged?  That would uncheck your toggle button when the popup closes.

    IsOpen="{Binding IsChecked, ElementName=toggleButton, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"

    Friday, May 10, 2013 2:35 PM
  • Hi Christine,

    Yes, I have used the Update source trigger, but still cant achieve my requirement.


    Friday, May 10, 2013 2:43 PM
  • Not sure why there is a problem.  The following XAML does what you want with no problems.


    <Window x:Class="MainWindow"
        Title="MainWindow" Height="350" Width="525">
            <ToggleButton x:Name="toggle" Margin="72,21,324,260">Click Me!</ToggleButton>
            <Popup StaysOpen="True" IsOpen="{Binding ElementName=toggle, Path=IsChecked}">
                <TextBlock Background="Red" Foreground="Wheat" >Is Show</TextBlock>

    Hope this helps


    Lloyd Sheen

    Friday, May 10, 2013 4:22 PM
  • After testing a bit, I can see the problems when StaysOpen is false.

    Take a look at this post...


    They give a very detailed description on reproducing the problem, what is happening and a solution.

    In addition the last post in that thread presents a different solution if working with commands. 

    Hope you can get it worked out quickly and easily.


    • Marked as answer by Lisa Zhu Tuesday, June 4, 2013 3:55 PM
    Friday, May 10, 2013 6:16 PM