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 6724325
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:40:35+00:00 2026-05-26T09:40:35+00:00

My user control context menu visibility can’t bind a dependency property. Any idea? Here

  • 0

My user control context menu visibility can’t bind a dependency property. Any idea?

Here is my WPF code

<UserControl.ContextMenu>
    <ContextMenu Visibility="{Binding ElementName=wellControl, Path=IsInCompactMode, Converter={StaticResource BooleanToVisibilityConverter}}">
    <MenuItem Command="local:GCommands.Edit" />
    <MenuItem Command="local:GCommands.Delete" />
    <MenuItem Command="local:GCommands.ExportFcsFiles" />
    <MenuItem Command="local:GCommands.BatchExportStatistics" />
    <Separator/>
    <MenuItem Command="local:GCommands.SaveAs" Header="Save As..." />
    </ContextMenu>
</UserControl.ContextMenu>

If I set Visibility=”Hidden” it will work for me.
like this:

<ContextMenu Visibility="Hidden"/>

If use this it won’t work

<ContextMenu Visibility="{Binding ElementName=wellControl, Path=IsInCompactMode, Converter={StaticResource BooleanToVisibilityConverter}}">

I’m pretty sure Visibility=”{Binding ElementName=wellControl, Path=IsInCompactMode, Converter={StaticResource BooleanToVisibilityConverter}}” has not problem, cuz it works for others.

here is my dependency property

public bool IsInCompactMode
        {
            get {return (bool)GetValue(IsInCompactModeProperty); }
            set {SetValue(IsInCompactModeProperty, value); }
        }
        public static readonly DependencyProperty IsInCompactModeProperty =
            DependencyProperty.Register("IsInCompactMode", typeof(bool), typeof(WellControl), new PropertyMetadata(false));

I tried this way, it seems it still doesn’t work, this is really weird!!!

<ContextMenu x:Name="menu" IsOpen="{Binding ElementName=wellControl, Path=IsInCompactMode}"> 

I’m really confuse about it, what’s wrong? “Binding ElementName=wellControl, Path=IsInCompactMode” works for other part of the user control, just doesn’t work for the weird context menu? it doesn’t make sence

  • 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-26T09:40:36+00:00Added an answer on May 26, 2026 at 9:40 am

    1> ContextMenu, Popups, DataGridColumns are not part of visual tree. So the binding using ElementName or RelativeSource wont work just like that.

    2> When you want the context menu to not display under particular situation use the triggers to unset the context menu from the visual itself.

          <TextBlock Text="ContextMenu is not shown when DataContext.IsShow is false"}">
                <TextBlock.Style>
                    <Style TargetType="{x:Type TextBlock}">
                        <Setter Property="ContextMenu"
                                Value="{StaticResource TextBlockContextMenu}" />
                       <Style.Triggers>
                           <DataTrigger Binding="{Binding IsShow}"
                                        Value="False">
                                <Setter Property="ContextMenu"
                                        Value="{x:Null}" />
                           </DataTrigger>   
                       </Style.Triggers>
                    </Style>
                </TextBlock.Style>
          </TextBlock>
    

    3> To attach these items to the visual tree, so that binding works, we use the proxy element method…

    Bind datagrid column visibility MVVM

    I prefer second step.

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

Sidebar

Related Questions

I have a context menu situated inside a User Control Resource. <UserControl.Resources> <ContextMenu x:Key=Menu1>
Is it possible for a user control to determine its context or its parent
I want to use Context.Items to store some info of a User Control like:
I am wanting to display a context menu when a user right-clicks on an
I have user control in my MVC2 app placed in the Content folder (it's
I have user control named DateTimeUC which has two textboxes on its markup: <asp:TextBox
I have a user control in a repeater that I need to pass data
I am creating a user control in C# and I am adding my own
I have created a user control to handle adding comments to certain business entities,
I am using the ToolStripDropDown to host the user control as the pop-up window.

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.