Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6567099
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T14:17:45+00:00 2026-05-25T14:17:45+00:00

I have WPF ContextMenu with MenuItems that support custom style. MenuItem is a ToggleButton.

  • 0

I have WPF ContextMenu with MenuItems that support custom style.
MenuItem is a ToggleButton. When the ToggleButton is checked the popup with textbox and close button appears.

<Style TargetType="MenuItem">
        <Setter Property="Foreground" Value="{StaticResource ForegroundColor}"/>
        <Setter Property="OverridesDefaultStyle" Value="true"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="MenuItem" >
                    <Grid>
                        <Border Name="Border" Height="25"
                        Background="{StaticResource BackgroundColor}">
                            <ToggleButton Name="tbtnOpenPopup">
                                <ToggleButton.Style>
                                    <Style TargetType="ToggleButton">
                                        <Setter Property="OverridesDefaultStyle" Value="True"/>
                                        <Setter Property="Template">
                                            <Setter.Value>
                                                <ControlTemplate TargetType="ToggleButton">
                                                    <Border Name="externalBorder" Background="Transparent"
                                                        BorderThickness="0">
                                                        <ContentPresenter Content="{TemplateBinding Content}"
                                                                      HorizontalAlignment="Stretch" 
                                                                      VerticalAlignment="Center"/>
                                                    </Border>
                                                    <ControlTemplate.Triggers>
                                                        <Trigger Property="IsMouseOver" Value="true">
                                                            <Setter TargetName="externalBorder" Property = "Background" Value="{StaticResource DropDownHighlightedBackgroundColor}"/>
                                                        </Trigger>
                                                    </ControlTemplate.Triggers>
                                                </ControlTemplate>
                                            </Setter.Value>
                                        </Setter>
                                    </Style>
                                </ToggleButton.Style>
                                <Grid>
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition/>
                                        <ColumnDefinition Width="7"/>
                                    </Grid.ColumnDefinitions>
                                    <ContentPresenter ContentSource="Header" VerticalAlignment="Center"
                                                      Margin="10,0,0,0"/>
                                    <Path Name="Arrow" Grid.Column="1"
                                          Data="M0,3 L5,0 L0,-3 L0,3 Z"
                                          Fill="{TemplateBinding Foreground}"
                                          VerticalAlignment="Center"/>
                                </Grid>
                            </ToggleButton>
                        </Border>
                        <Popup Grid.ColumnSpan="2"
                            Name="Popup"
                            Placement="Right"
                            AllowsTransparency="True" 
                            Focusable="False"
                            StaysOpen="True"
                            IsOpen="False"
                            PopupAnimation="None">
                            <Grid Name="DropDown"
                            SnapsToDevicePixels="True"                
                            MinWidth="{TemplateBinding ActualWidth}">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition/>
                                    <ColumnDefinition Width="22"/>
                                </Grid.ColumnDefinitions>
                                <Border MinHeight="25" Grid.ColumnSpan="2"
                                    x:Name="DropDownBorder"
                                    Background="{StaticResource DropDownBackgroundColor}"
                                    BorderThickness="0"/>
                                <TextBlock Text="Some text" VerticalAlignment="Top"
                                       HorizontalAlignment="Stretch"/>
                                <Button Name="closeButton" 
                                    Content="X"
                                    Grid.Column="1"
                                    VerticalAlignment="Top"
                                    HorizontalAlignment="Right"/>
                            </Grid>
                        </Popup>
                    </Grid>
                    <ControlTemplate.Triggers>
                        <Trigger SourceName="tbtnOpenPopup" Property="IsChecked" Value="true">
                            <Setter TargetName="Popup" Property="IsOpen" Value="true"/>
                            <Setter TargetName="Arrow" Property="Data" Value="M5,3 L0,0 L5,-3 L5,3 Z"/>
                        </Trigger>
                        <Trigger SourceName="closeButton" Property="IsPressed" Value="true">
                            <Setter TargetName="tbtnOpenPopup" Property="IsChecked" Value="false"/>
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

I want the popup textbox to close when the “closeButton” pressed, and the ContextMenu to stays open. But when the “closeButton” pressed the ContextMenu closed.

I couldn’t understand why it’s happining.

Have you any ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T14:17:45+00:00Added an answer on May 25, 2026 at 2:17 pm

    Generally speaking, a context menu will close when focus is set elsewhere. Clicking your ToggleButton is within the ContextMenu, so that’s okay – but when you click on the close button, you’re clicking outside the ContextMenu and it closes.

    (Remember that a ContextMenu is a popup, and not part of the visual tree of the owner control.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a wpf application that has a button for for each folder under
In our WPF app we have a global style with TargetType={x:Type ContextMenu} . I
I have WPF Span that is used as a source to a TextBlock. I
I have a tree in WPF that has no root node, but has defined
I have a WPF contextmenu and I want to add an Item with Icon
I have WPF app that processes a lot of urls (thousands), each it sends
I have WPF window that uses a dockpanel and the menu control. I have
I have WPF App, that needs to be update some data , after computer
I have WPF application. After testing my app on Windows7 and realized that opening
I have a WPF application with a NotifyIcon defined in a ResourceDictionary that is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.