How to change PopupButton.StayOpen in PopupButtonContent?

WPF Studio, Themes, and Shared Library for WPF Forum

Posted 6 months ago by Yuki
Version: 23.1.3
Avatar

Hello,

How to change PopupButton.StayOpen in PopupButtonContent?

I have checked with the following source code.

After I ticked StayOpenCheckBox, PopupButton.StayOpen = true is not reflected immediately.

--> Popup will be closed when click outside of PopupContent.

Xaml:

<Window
    x:Class="PopupSample.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:shared="http://schemas.actiprosoftware.com/winfx/xaml/shared"
    Title="MainWindow"
    mc:Ignorable="d">
    <Grid>
        <shared:PopupButton
            x:Name="MyPopupButton"
            HorizontalAlignment="Left"
            VerticalAlignment="Top"
            Content="Popup Button">
            <shared:PopupButton.PopupContent>
                <CheckBox
                    x:Name="StayOpenCheckBox"
                    Margin="8"
                    Checked="OnStayOpenCheckBoxCheckedChanged"
                    Content="StayOpen"
                    Unchecked="OnStayOpenCheckBoxCheckedChanged" />
            </shared:PopupButton.PopupContent>
        </shared:PopupButton>
    </Grid>
</Window>

Code behind:

using System.Windows;

namespace PopupSample
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void OnStayOpenCheckBoxCheckedChanged(object sender, RoutedEventArgs e)
        {
            MyPopupButton.StaysOpen = StayOpenCheckBox.IsChecked == true;
        }
    }
}

Comments (3)

Posted 6 months ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hello,

The PopupButton.StaysOpen property needs to be set prior to the popup being opened.  It tells the PopupButton to attach to some extra events that aren't watched otherwise.  That's why it's not applying immediately when you set it while the popup is already open.


Actipro Software Support

Posted 6 months ago by Yuki
Avatar

Hello,

Thank you for you reply.

I'd like to show dialog by clicking button in PopupContent and set PopupButton.StayOpen = true during showing dialog only.

After close the dialog, I want to close popup by click outside of popup content.

Is there any good solution?

<Window
    x:Class="PopupSample.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:shared="http://schemas.actiprosoftware.com/winfx/xaml/shared"
    Title="MainWindow"
    mc:Ignorable="d">
    <Grid>
        <shared:PopupButton
            x:Name="MyPopupButton"
            HorizontalAlignment="Left"
            VerticalAlignment="Top"
            Content="Popup Button">
            <shared:PopupButton.PopupContent>
                <Button
                    x:Name="ShowDialogButton"
                    Margin="8"
                    Click="ShowDialogButton_Click"
                    Content="ShowDialog" />
            </shared:PopupButton.PopupContent>
        </shared:PopupButton>
    </Grid>
</Window>
using System.Windows;

namespace PopupSample
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void ShowDialogButton_Click(object sender, RoutedEventArgs e)
        {
            MyPopupButton.StaysOpen = true;

            var window = new Window { Title = "SubWindow", Height=200, Width=400 };
            window.ShowDialog();

            MyPopupButton.StaysOpen = false;
        }
    }
}
Answer - Posted 6 months ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hello,

Unfortunately the only thing you could do here is try to close the popup, then set StaysOpen=true, the reopen the popup, and show the Window.  That might work.


Actipro Software Support

The latest build of this product (v24.1.2) was released 9 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.