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

  • Home
  • SEARCH
  • 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 3597722
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T20:09:15+00:00 2026-05-18T20:09:15+00:00

I want to try out a small, custom ValueConverter in a class which after

  • 0

I want to try out a small, custom ValueConverter in a class which after being instantiated (via default constructor, which only calls InitializeComponents() ), is given another DataContext, specifically an instance of a ViewModel.

Using a StaticResource within the Binding does not work at all (yields a NullReferenceException), since the DataContext has since then been changed (is not this anymore).

I’ve tried putting DataContext = this; before the InitializeComponents call, no change.
Should I be looking into this MarkupExtension gizmo (as described in this article) ?

I’ve also tried creating an instance of the custom Value Converter within the ViewModel (the current DataContext), doesn’t help either.

I can provide additional details at all times. Thank you in advance !

I’m trying to display a ContextMenu within the TextBlock. The ContextMenu contains a sole MenuItem. The header of the MenuItem can be “Settings” for instance. The Children (rendered as MenuItems as well) of the said MenuItem stem from an Enum, hence the ItemsSource on the MenuItem.

Now all is getting displayed nicely, yet I am trying to make one of the Children (e.g. a member of the Enum) to be selected per default, since there is already a default Setting. Further background info can be found in my other question.

Edit :

... 
<UserControl.Resources>
  <Helpers:DisplayTypeToDefaultValueConverter x:Key="displayTypeConverter" />
</UserControl.Resources>
...

<TextBlock x:Name="InstructionLabel" 
           TextWrapping="Wrap" Text="{Binding Path=SelectedNodeText}" 
           Grid.RowSpan="1">

  <TextBlock.ContextMenu>
    <ContextMenu>
      <MenuItem Header="Settings" Name="SettingsPop" 
                DataContext="{Binding}" 
                ItemsSource="{Binding Source={StaticResource DisplayTypeValues}}"
                IsCheckable="True"
                Click="SettingsType_Click">   

        <MenuItem.ItemContainerStyle>
          <Style TargetType="MenuItem">
            <Setter Property="Header" Value="{Binding}"/>
            <Setter Property="IsChecked">
              <Setter.Value>
                <Binding Converter="{StaticResource displayTypeConverter}" />
              </Setter.Value>
            </Setter>
          </Style>
        </MenuItem.ItemContainerStyle> 

     </ContextMenu>
  </TextBlock>

I’ve only now realized that it’s the dreaded ContextMenu. That’s the problem, isn’t it ?

  • 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-18T20:09:15+00:00Added an answer on May 18, 2026 at 8:09 pm

    Used an easier solution, as highlighted in my other related question.
    Thank you for your input !

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

Sidebar

Related Questions

I want to try out a small, custom ValueConverter in a class which after
I want to try out SICP with Python. Can any one point to materials
I have a small project I want to try porting to Python 3 -
I want to try out a patch on gist that modifies the source code
I want to try figure out how to get the <title>A common title</title> <meta
I want to try to convert a string to a Guid, but I don't
I want to try PartCover for code coverage. I'm running Visual Studio 2008 Professional
I want to give Windows Server 2008 a try as a .NET developer and
I try to write a simple Markdown parser in JavaScript. Therefore I want to
I would like to to try Emacs, and want to give it the best

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.