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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T05:08:22+00:00 2026-06-13T05:08:22+00:00

I am working with the sample code for the stock trader reference implementation. http://prism4.googlecode.com/svn/trunk/Prism4/

  • 0

I am working with the sample code for the stock trader reference implementation.

http://prism4.googlecode.com/svn/trunk/Prism4/

There is a list of stocks in PositionSummaryView.xaml. In the list of stocks I added a GridViewColumn with a Textbox that displays the name of the stock. I try to call a command in the ViewModel when the user hits the enterkey by using the behaviour ReturnCommandBehavior.

The command is not hit when I press enter in the textbox. When I have the same textbox outside of the list, the command is hit.

This works outside of the ListView

<TextBox Grid.Column="0"  Text="test"    Infrastructure:ReturnKey.Command="{Binding Path=UpdateTickerSymbolCommand}"  ></TextBox>

This is the bindings I tried in the TextBox, but none works:

 <TextBox Grid.Column="0"  Text="{Binding  Path=TickerSymbol}"  
                                  Infrastructure:ReturnKey.Command="{Binding Path=UpdateTickerSymbolCommand, RelativeSource={RelativeSource AncestorType={x:Type ListView}}}"  ></TextBox>

Second try

  <TextBox Grid.Column="0"  Text="{Binding  Path=TickerSymbol}"   Infrastructure:ReturnKey.Command="{Binding ElementName=root,Path= UpdateTickerSymbolCommand}" ></TextBox>

Here is the viewmodel:

using System.ComponentModel.Composition;
using System.Windows.Input;
using Microsoft.Practices.Prism.Events;
using Microsoft.Practices.Prism.ViewModel;
using StockTraderRI.Infrastructure;
using StockTraderRI.Modules.Position.Controllers;
using Microsoft.Practices.Prism.Commands;

namespace StockTraderRI.Modules.Position.PositionSummary
{
    [Export(typeof(IPositionSummaryViewModel))]
    [PartCreationPolicy(CreationPolicy.NonShared)]
    public class PositionSummaryViewModel : NotificationObject, IPositionSummaryViewModel
    {
        private PositionSummaryItem currentPositionSummaryItem;

        private readonly IEventAggregator eventAggregator;

        public IObservablePosition Position { get; private set; }


        private ICommand updateTickerSymbolCommand;

        public ICommand UpdateTickerSymbolCommand { get { return this.updateTickerSymbolCommand; } }

        [ImportingConstructor]
        public PositionSummaryViewModel(IOrdersController ordersController, IEventAggregator eventAggregator, IObservablePosition observablePosition)
        {
            this.eventAggregator = eventAggregator;
            this.Position = observablePosition;

            BuyCommand = ordersController.BuyCommand;
            SellCommand = ordersController.SellCommand;
            updateTickerSymbolCommand = new DelegateCommand<string>(this.UpdateTickerSymbol); ;

            this.CurrentPositionSummaryItem = new PositionSummaryItem("FAKEINDEX", 0, 0, 0);
        }

        private void UpdateTickerSymbol(string tickerSymbol)
        {

        }



        public ICommand BuyCommand { get; private set; }

        public ICommand SellCommand { get; private set; }

        public string HeaderInfo
        {
            get { return "POSITION"; }
        }

        public PositionSummaryItem CurrentPositionSummaryItem
        {
            get { return currentPositionSummaryItem; }
            set
            {
                if (currentPositionSummaryItem != value)
                {
                    currentPositionSummaryItem = value;
                    this.RaisePropertyChanged(() => this.CurrentPositionSummaryItem);
                    if (currentPositionSummaryItem != null)
                    {
                        eventAggregator.GetEvent<TickerSymbolSelectedEvent>().Publish(
                            CurrentPositionSummaryItem.TickerSymbol);
                    }
                }
            }
        }
    }
}

What do I need to hit UpdateTickerSymbol when pressing enter key?

EDIT

I now saw that I misinterpreted

Binding ElementName=root

in some sample code. I thought root is a keyword, but it is the key that has to be given to a parent control in the view

Thats why I used

  <StackPanel x:Name="LayoutRoot" >

in a parent controll now and

<TextBox Grid.Column="0"  Text="{Binding  Path=TickerSymbol}"   Infrastructure:ReturnKey.Command="{Binding ElementName=LayoutRoot, Path=UpdateTickerSymbolCommand}" ></TextBox>

for the TextBox, but the command is still not hit.

I also tried the above syntax with a Button in the sample, and it worked

<Button Grid.Column="0" Command="{Binding Path=DataContext.BuyCommand, ElementName=LayoutRoot}" CommandParameter="{Binding Path=TickerSymbol}" AutomationProperties.AutomationId="ActionsBuyButton" Template="{StaticResource AddButtonTemplate}"  Cursor="Hand" Width="30" />
  • 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-13T05:08:23+00:00Added an answer on June 13, 2026 at 5:08 am

    I downloaded the source. The TextBox seemed to have disappeared. Changing the Command of the TextBox to DataContext.BuyCommand “fixed” the “problem”. The command “UpdateTickerSymbolCommand” also seemed no longer available, so I wasn’t able to test this as well. The current source also doesn’t have a reference to the StackPanel (LayoutRoot), so this also I was unable to track. I think the key problem here was the Command not having been set properly.

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

Sidebar

Related Questions

Can anyone provide a working sample code to convert following Oracle DB table with
Here is a sample code I'm working on: <%@ Page Language=C# AutoEventWireup=true CodeFile=Default.aspx.cs Inherits=_Default
I haven't been able to get this working and all of the sample code
I'm working through Beej's socket tutorial . Using the sample code I've created a
I am using Slidesjs it working fine in below url http://www.mysoko.in/demo/Simple/ And same code
I have been working with the google docs api found here: https://developers.google.com/google-apps/documents-list/#introduction This issue
I'm working on a simple GUI code editor in Python, and I want to
I have a simple code fragment in JS working with prototype inheritance. function object(o)
I have a very simple code, which annoyingly was working and for the life
I have the simple following code, which is working in a ruby (not rails)

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.