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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T22:01:13+00:00 2026-05-13T22:01:13+00:00

New to wpf and through a learning curve. I have a userControl with a

  • 0

New to wpf and through a learning curve.
I have a userControl with a Toolbar Save Button and a TextBox.
What I am trying to achieve is as follows

When I press the save Button in the toolbar I should record in the textbox that I am about to save and that I have saved the customer (CustomerView UserControl)
I seem to have 2 problems

1) that the SaveCommand is not hooked I thought I had hooked it

2) is not writing the action to the textbox.

Could you tell me where I am going wrong?
Thanks a lot!!!

MainWindow.xaml

<Window x:Class="MyCompany.CustomerStore.MainWindow"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:view="clr-namespace:MyCompany.CustomerStore.Views"
      Title="MainWindow" Height="350" Width="525">
   <Grid>
       <view:CustomerView></view:CustomerView>
   </Grid>

  CustomerView.xaml


    <UserControl x:Class="MyCompany.CustomerStore.Views.CustomerView"
          xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
          xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
          xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
          xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
          mc:Ignorable="d" 
          d:DesignHeight="300" d:DesignWidth="300">
   <Grid>
       <DockPanel LastChildFill="True">
           <ToolBar DockPanel.Dock="Top">
               <Button Command="{Binding Path=SaveCommand}">Save</Button>
           </ToolBar>
           <TextBox Name="txtPrintAction" Text="{Binding CustomerLog, Mode=TwoWay}"></TextBox>
       </DockPanel>
   </Grid>

  CustomerModel.cs


 public class CustomerModel
  {
      public string FirstName { get; set; }
      public string LastName { get; set; }
      public string CustomerLog { get; set; }
  }

  CustomerViewModel.cs

  public class CustomerViewModel:WorkspaceViewModel,ICustomerViewModel
  {
      readonly CustomerModel _customerModel;

      RelayCommand _saveCommand;

      public CustomerViewModel(CustomerModel customer)
      {
          _customerModel = customer;
      }
      public string FirstName
      {
          get { return _customerModel.FirstName; }
          set
          {                 
              _customerModel.FirstName = value;
              base.OnPropertyChanged("FirstName");
          }
      }
      public string LastName
      {
          get { return _customerModel.LastName; }
          set
          {
              _customerModel.LastName = value;
              base.OnPropertyChanged("LastName");
          }
      }
      public string CustomerLog
      {
          get { return _customerModel.CustomerLog; }
          set
          {
              _customerModel.CustomerLog = value;
              base.OnPropertyChanged("CustomerLog");
          }
      }
      public ICommand SaveCommand
      {
          get
          {
              if (_saveCommand == null)
              {
                  _saveCommand = new RelayCommand(param => Save(), param => CanSave);
              }
              return _saveCommand;
          }
      }

      private  void Save()
      {
          AppendToLog("I am about to save");

          //Pretend we have saved the customer

          AppendToLog("CustomerSaved");
      }

      internal void AppendToLog(string text)
      {
          _customerModel.CustomerLog += text + Environment.NewLine; ;
          OnPropertyChanged("CustomerLog");
      }

      static bool CanSave
      {
          get
          {
              return true; 
          } 
      }
  • 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-13T22:01:13+00:00Added an answer on May 13, 2026 at 10:01 pm

    Where do you declare a relationship between the view

    x:Class=”MyCompany.CustomerStore.Views.CustomerView

    and the model class CustomerViewModel?

    I don’t see that anywhere.

    I think you need to set the DataContext of the View to the Model.

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

Sidebar

Related Questions

I'm VERY new to WPF, and still trying to wrap my head around binding
I'm new to WPF and come from a WinForms background and have a fairly
Learning WPF nowadays. Found something new today with .Net dependency properties. What they bring
I'm considering integrating some D3D code I have with WPF via the new D3DImage
I started a new WPF project in VS2008 and then added some code to
I am fairly new to WPF and I am having a problem with inheriting
I'm new to WPF and data binding so hopefully I can explain the problem
A bit new with WPF...It seems like not matter what I change with horizontal
Ok... I'm new to WPF, but I kind of know how to do things
Hello there and Merry Christmas !!! I am new to WPF and I am

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.