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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T20:48:57+00:00 2026-05-21T20:48:57+00:00

We have a screen and its view model: public class ScreenViewModel : BaseViewModel {

  • 0

We have a screen and its view model:

public class ScreenViewModel : BaseViewModel
{
    [NotifyPropertyChanged]
    public List<Node> Nodes { get; set; }

    public ICommand NodeClickedCommand { get; set; }

    public ScreenViewModel()
    {
        NodeClickedCommand = new RelayCommand(NodeClicked);
        // ....
        // Some code that binds Nodes.
        // ....
    }

    private void NodeClicked()
    {
        MessageBox.Show("This is never shown");
    }
}

On this page we have custom control (CustomControl) and following xaml to bind the command:

<UserControl x:Class="ScreenView"
    x:Name="Screen"
    >
     <CustomControl Nodes="{Binding Nodes}">
                <CustomControl.ItemTemplate>
                    <DataTemplate>
                                <Button Command="{Binding ElementName=Screen,
                                     Path=DataContext.NodeClickedCommand}">
                                    <TextBlock>hello</TextBlock>
                                </Button>
                    </DataTemplate>
                </CustomControl.ItemTemplate>
        </CustomControl>

Our custom SL control uses the above template (DataTemplate) to display it’s children:

foreach(Node node in Nodes)
{
    FrameworkElement frameworkElement = (FrameworkElement)ItemTemplate.LoadContent();
    frameworkElement.DataContext = node ;
    this._canvas.Children.Add(frameworkElement);
}

We are sure that:

  • ViewModel is correctly bound to View
  • All nodes are displayed correctly
  • Regular binding works correctly
  • There are no binding warnings in VS
  • Command binding works if we bind with Command=”{Binding NodeClickedCommand}”, but of course this binds to command that should exist on single node and we want to bind to command that exists on the screen view model.
  • Simmilar scenario works with ListBox and ListBox.ItemTemplate

The problem is that NodeClickedCommand is never bound, why?

  • 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-21T20:48:58+00:00Added an answer on May 21, 2026 at 8:48 pm

    It seems that using ContentPresenter instead of ItemTemplate.LoadContent solves this issue:

    foreach(Node node in Nodes)
    {
        ContentPresenter contentPresenter = new ContentPresenter();
        contentPresenter.Content = node;
        contentPresenter.ContentTemplate = ItemTemplate;
        this._canvas.Children.Add(contentPresenter);
    
    //    FrameworkElement frameworkElement = (FrameworkElement)ItemTemplate.LoadContent();
    //    frameworkElement.DataContext = node ;
    //    this._canvas.Children.Add(frameworkElement);
    }
    

    Thanks to dain as he pointed me to the right direction.

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

Sidebar

Related Questions

I have a screen with a ListBox of items. The item template contains an
I sometimes need to use Visual Studio when I have limited screen real estate
Java 1.5, Linux I do have a screen which contains different textareas and textfields.
I have a 1920x1200 screen an would like to customize VS2008 code windows to
I have a touch screen kiosk that displays a webpage and a pdf document.
I have a login screen that I force to be ssl, so like this:
What I'm doing is I have a full-screen form, with no title bar, and
I'd like my application to have a full-screen mode. What is the easiest way
In a C# windows forms application. I have a splash screen with some multi-threaded
I have been asked to standardize the screen saver and desktop background used by

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.