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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T06:57:09+00:00 2026-06-04T06:57:09+00:00

The DataContext for my window is an IDictionary>. Can anyone explain to me why

  • 0

The DataContext for my window is an IDictionary>.

Can anyone explain to me why this works fine:

<Style x:Key="MenuItemStyle">
    <Setter Property="MenuItem.Header" Value="{Binding Ticker}"/>
</Style>
<Style x:Key="ContextMenuStyle">
    <Setter Property="MenuItem.Header" Value="{Binding Key}"/>
    <Setter Property="MenuItem.ItemsSource" Value="{Binding Value}"/>
    <Setter Property="MenuItem.ItemContainerStyle" Value="{StaticResource MenuItemStyle}"/>
</Style>
<ContextMenu ItemContainerStyle="{StaticResource ContextMenuStyle}" ItemsSource="{Binding Quotes}" />

But this does not:

<Style TargetType="{x:Type ContextMenu}" x:Key="ContextMenuStyle">
    <Setter Property="MenuItem.Header" Value="{Binding Key}"/>
    <Setter Property="MenuItem.ItemsSource" Value="{Binding Value}"/>
    <Setter Property="MenuItem.ItemContainerStyle">
        <Setter.Value>
            <Style TargetType="{x:Type MenuItem}">
                <Setter Property="Header" Value="{Binding Ticker}"/>
            </Style>
        </Setter.Value>
    </Setter>
</Style>
<ContextMenu ItemContainerStyle="{StaticResource ContextMenuStyle}" ItemsSource="{Binding Quotes}" />

EDIT: if i remove T’argetType=”{x:Type ContextMenu}”‘, it works fine. i don’t clearly understand why however.

thanks

  • 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-06-04T06:57:10+00:00Added an answer on June 4, 2026 at 6:57 am

    You need to change the value of the TargetType from ContextMenu to MenuItem. The ItemContainerStyle property of the ContextMenu sets the style to the container element of your ContextMenu, in this case a MenuItem. However you set the target type of the style to ContextMenu so it cannot work. See this link for more details.

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

Sidebar

Related Questions

Here is the code : <Window.DataContext> <local:MainWindowViewModel /> </Window.DataContext> <Window.Resources> <Style x:Key=RadioToggleButtonStyle TargetType=RadioButton> <Setter
I've set up my DataContext like this: <Window.DataContext> <c:DownloadManager /> </Window.DataContext> Where DownloadManager is
I am binding WPF with Entity-Framework. The Window.DataContext property is set to a Quote.
I have a list (see below) contained in a window. The window's DataContext has
I have a window, and its datacontext is a viewmodel. now, outside the scope
Duplicate of : Why are DataContext and ItemsSource not redundant? In WPF we can
I wish to define the DataContext of my window from an external class to
I have some problem to access the Window's DataContext from within a DataGrid. The
I have a WPF Window with a view model set as its DataContext, and
I'm trying to get a Window's datacontext to be set to itself, but I

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.