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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T13:46:00+00:00 2026-05-30T13:46:00+00:00

I have a specialized UserControl to play media content called PlayerView . The control

  • 0

I have a specialized UserControl to play media content called PlayerView.
The control has its own commands (readonly, not provided by client).

public partial class PlayerView
{
    public PlayerView()
    {
        InitializeComponent();
        PlayCommand = new RelayCommand(() =>
            {
                // Play some media: audio/video.
            });
    }

    ...

    #region PlayCommand property

    private static readonly DependencyPropertyKey PlayCommandPropertyKey = DependencyProperty.RegisterReadOnly(
      "PlayCommand",
      typeof(ICommand),
      typeof(PlayerView),
      new PropertyMetadata());

    public static readonly DependencyProperty PlayCommandProperty = PlayCommandPropertyKey.DependencyProperty;

    public ICommand PlayCommand
    {
        get { return (ICommand)GetValue(PlayCommandProperty); }
        private set { SetValue(PlayCommandPropertyKey, value); }
    }

    #endregion

    ...
}

The play command of the control works fine from XAML:

<Controls:PlayerView x:Name="PlayerView" />
<Button Command="{Binding ElementName=PlayerView, Path=PlayCommand, Mode=OneWay}" Content="Play" />

But currently, I am implemeting slideshow feature and I would like to execute the play command of the control from the ViewModel.

public class SlideshowViewModel : ViewModelBase
{
    // Stores collection of audio/video clips to be played by the PlayerView.

    // Assume that this ViewModel should invoke PlayerView PlayCommand.
}

public class MainViewModel : ViewModelBase
{
    // Stores a lot of stuff.

    public SlideshowViewModel Slideshow { get; }
}

Class diagram

The question is: how the SlideshowViewModel can execute the PlayCommand of this control? Is there a best practice?

  • 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-30T13:46:01+00:00Added an answer on May 30, 2026 at 1:46 pm

    If I am understanding your issue correctly, the ViewModel should contain the implementation of the Command, not the View. This would be a truer MVVM implementation, and then the VM can call that command from within itself, if necessary.

    edit:

    to answer your question,

    public partial class PlayerView : IHaveAPlayCommand
    {
    public PlayerView()
    {
          this.DataContext = new ViewModel(this);
    }
    }
    
    
    public class ViewModel
    {
          IHaveAPlayCommand view;
          public ViewModel(IHaveAPlayCommand view)
          {
               this.view = view
          }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

At first sorry for bad english, Im deafinitely not specialized into math-english. I have
I'm creating a UserControl that's a specialized ListBox/View (type not relevant). Now I'm faced
For a specialized purpose with Aweber regarding a newsletter subscription, I have a page
I have a specialized search engine that passes search criteria from the Search page
I have a specialized string dictionary of (string, string) (_RulesAndTheirDescriptions) that contains the name
Have looked so long for a library specialized in dealing with iPhone Accelerometer but
I have to implement template specialization, in implementing the constructor for specialized template class
I have a template class that has a template member function that needs to
all. I have a usercontrol NumericTextBox that only allows numeric entries. I need to
I have a set of specialized templates. Now I want to create specialized templates

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.