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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T12:46:45+00:00 2026-06-02T12:46:45+00:00

I obviously don’t get this somewhere. I have created a UserControl, the bare bones

  • 0

I obviously don’t get this somewhere.

I have created a UserControl, the bare bones of which is:

private readonly DependencyProperty SaveCommandProperty =
      DependencyProperty.Register("SaveCommand", typeof(ICommand),
                                  typeof(ctlToolbarEdit));

private readonly DependencyProperty IsSaveEnabledProperty = 
      DependencyProperty.Register("IsSaveEnabled", typeof(bool), 
        typeof(ctlToolbarEdit), new PropertyMetadata(
           new PropertyChangedCallback(OnIsSaveEnabledChanged)));

public ctlToolbarEdit()
{
   InitializeComponent();
}

public bool IsSaveEnabled
{
   get { return (bool)GetValue(IsSaveEnabledProperty); }
   set { SetValue(IsSaveEnabledProperty, value); }
}

public static void OnIsSaveEnabledChanged(DependencyObject d,
   DependencyPropertyChangedEventArgs e)
{
   ((ctlToolbarEdit)d).cmdSave.IsEnabled = (bool)e.NewValue;
}

#region Command Handlers
public ICommand SaveCommand
{
   get { return (ICommand)GetValue(SaveCommandProperty); }
   set { SetValue(SaveCommandProperty, value); }
}

private void cmdSave_Click(object sender, RoutedEventArgs e)
{
   if (SaveCommand != null) 
      SaveCommand.Execute(null);
}

#endregion

Excellent. You can see what I am doing … handling the click event of the button, and basically firing up the command.

The form (lets call that Form1 for the time being … but note that this is actually a UserControl: common practice, I believe, in MVVM) that is hosting the control has the following line:

<ctl:ctlToolbarEdit HorizontalAlignment="Right" Grid.Row="1" 
   SaveCommand="{Binding Save}" IsSaveEnabled="{Binding IsValid}" />

This works great. I have an ICommand in my ViewModel called ‘Save’ and the ViewModel is correctly presenting the IsValid property.

So far so very good.

Now I want to have my new usercontrol also on Form2 (which is also a usercontrol – common practice, I believe, on MVVM). As it happens, Form1 and Form2 are on the screen at the same time.

It compiles, but I get a runtime exception:

‘SaveCommand’ property was already registered by ‘ctlToolbarEdit’.”

… leading me to believe that I don’t get ‘commands’ at all.

Why can I not use my usercontrol in more than one place?

If I cannot, what would you suggest is another way to do this?

Very frustrating!

Thanks for any help.

  • 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-02T12:46:47+00:00Added an answer on June 2, 2026 at 12:46 pm

    Try making your dependency properties static. Otherwise it is getting re-registered every time you instantiate a new control. Your usage of the MVVM commands looks good otherwise and sounds like you have a good grasp on it.

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

Sidebar

Related Questions

I obviously don't know what I'm doing. I have finally got this PowerShell command
I don't seem to understand the purpose of XMLString::transcode(XMLCh*) and XMLString::transcode(char*) , because obviously
This must be a dumb question, but I don't see any obvious references. How
Obviously I could create a Calendar object with the date and use get(DAY) on
I have a found a 3rd party Look and Feel which I would really
Lets say I have something like this: http://gyazo.com/642987562175afc6d11a962762327744.png?1329570534 Basically, the user fills out this
Think at this scenario: I have a c# windows form application. This application was
From time to time I'll have a string in my project which is simply
I have created a stream based on a stateless protocol, think 2 web servers
I have a commit on a public repository. I would like this commit to

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.