I have a listboxitem, which when clicked, produces an adorner holding a custom control made of a textbox label and a MediaElement. All is well and the selected movie plays. The listbox was subclassed into a custom control as "ChartCanvas".
My problem: I have the controls for the movie in a different part of the visual tree. It is simple to get the command to playmovie to the "ChartCanvas", but I do not know how to send this command to the overlaying adorner control.
The basic code that creates the adorner is:
public UIElementAdorner(UIElement adornedElement, UIElement element)
: base(adornedElement)
{
m_element = element;
_adornedElement = adornedElement as Border;
if (_adornedElement is null)
throw new ArgumentException("This adorner requires a Border element of
sizing in MeasureOverride and Arrangement.");
}
public void Add()
{ // These commands are absolutely needed for correct MediaElement/Adorner usage.
AddLogicalChild(m_element);
AddVisualChild(m_element);
... ...
}
The ChartCanvas code for PlayMovieCommand:
private ICommand _playMovie;
public ICommand PlayMovieCommand
{
get
{
if (_playMovie == null)
{
_playMovie = new RelayCommand(
p => true,
p => this.PlayMovie());
}
return _playMovie;
}
}
private void PlayMovie()
{
Commands.PlayMovieCommand.Execute(null,null);
}
And in the MovieControl adorner--this code is never reached:
public MovieControlForChartCanvas()
{
InitializeComponent();
CommandBindings.Add(new CommandBinding(Commands.PlayMovieCommand, OnPlayMovieCommand));
}
In short, how can an adorner catch a routedcommand?
Thank you for any help.