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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T02:23:44+00:00 2026-05-17T02:23:44+00:00

I have created a Silverlight User Control. The markup is: <StackPanel Grid.Row=4 Grid.Column=0 Orientation=Horizontal

  • 0

I have created a Silverlight User Control. The markup is:

<StackPanel Grid.Row="4" Grid.Column="0" Orientation="Horizontal" Width="Auto" Margin="5">
    <Button Content="OK" Margin="0,0,5,5" MinWidth="50" Command="{Binding OKCommand}"  />
</StackPanel>

The code behind declares a Dependency property ‘OKCommand’ as:

public ICommand OKCommand
{
    get
    {
        return (ICommand)GetValue(OKCommandProperty);
    }
    set
    {
        SetValue(OKCommandProperty, value);
    }
}

public static readonly DependencyProperty OKCommandProperty
    = DependencyProperty.Register("OKCommand", typeof(ICommand), typeof(TestUserControl), new PropertyMetadata(null, OKCommandProperty_PropertyChangedCallback));

private static void  OKCommandProperty_PropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
{      
}

Now I want to use the user control on another page where which is the View & the ViewModel defines the command to which I want the OKCommand to be bound. The XAML markup is as such:

<local:TestControl OKCommand="{Binding Path=TestControlOk}"/>

However when I click the button it does not execute anything. Any clues as to what I am doing wrong here.

  • 1 1 Answer
  • 3 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-17T02:23:45+00:00Added an answer on May 17, 2026 at 2:23 am

    You need to show the view model that contains the TestControlOk property so we can tell if that’s part of the problem.


    UserControls do not register themselves as the data context automatically so the binding inside the user control won’t have anything to bind to. Do you have

    this.DataContext = this;
    

    anywhere in the UserControl codebehind to enable your first binding to actually work?

    Alternatively, you can do something like so:

    <UserControl .....
        x:Name="MyUserControl">
        <StackPanel Grid.Row="4" Grid.Column="0" Orientation="Horizontal" Width="Auto" Margin="5">
            <Button Content="OK" Margin="0,0,5,5" MinWidth="50" 
                Command="{Binding OKCommand, ElementName=MyUserControl}"  />
        </StackPanel>
    </UserControl>
    

    Note the ElementName= part of the binding pointing to the root UserControl element in your XAML.

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

Sidebar

Related Questions

I have created a user control in Silverlight which basically animates the size of
I have created a new silverlight business application in visual studio. It auto generates
I have a User Control that I need to programmatically add to a Silverlight
I have created successfully a wpf user control inheritance like this: <base:BaseUserControl x:Class=wpfcontrolinheritance.InheritedUserControl xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation
I have to create Silverlight User Control with public properties that should be used
I have created a user control in silver-light. I will use this control in
I have created a lookless control using silverlight 4. This control contains a textbox
I have created a Windows Phone 7.5 Silverlight application. Most of the design and
I have created a web application with a Silverlight project embedded in it, using
(Using Silverlight 4.0 and VS 2010) So I have created a property called Rank

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.