How to get the ControllerContainer grid element?

Apr 28, 2010 at 3:00 PM

Hi all,


I want to get the ControllerContainer from the player object to make some modification on it (basically, add a new button).

How is it possible?

I'm using the 1.1 SMF.


Thanks a lot for your help.


Apr 28, 2010 at 3:04 PM

The easiest way is to just edit a copy of the template in Blend. Otherwise if you don't have blend you can copy the template out of the generic.xaml in the Microsoft.SilverlightMediaFramework.Player project

Apr 28, 2010 at 3:09 PM

Thanks a lot DarthObiwan.

I've thought about that. That is the easiest way, you are right. Nevertheless, the best for my project is to manage that using pure C# code behind.

Apr 28, 2010 at 3:51 PM

What you can do, and I have done as well for my project is to extend the player and create my own generic.xaml that it uses as the default template. I have a custom player class that exposes 5 new template parts and some new visual states. In the constructor of the custom player I set the DefaultStyleKey to the type of my class and that points to the version in my themes/generic.xaml.

Doing this I can control the display by code still and have my new parts in there.

Finding the grid via code just takes walking the visual tree.

player.GetVisualAncestors().Where(x => x is Grid && ((Grid) x).Name == "ControllerContainer ").FirstOrDefault();
That should work to find the grid

Apr 28, 2010 at 3:53 PM

Hey! thanks a lot for this trick! I'll experiment that



Apr 28, 2010 at 3:56 PM

small typo in my code.. extra space on the name == :) that's what I get for copy and pasting

Apr 28, 2010 at 4:06 PM

Thanks DarthObiwan.

Just a quick question (sorry, I'm noob with this framework) : how do you extend the player?


Apr 28, 2010 at 5:17 PM

Just extend it like any other class.

public class MyPlayer:Player


Apr 28, 2010 at 5:18 PM

Yep, that's what I've made ;)


In fact, that was a dumb question :) Really soory