The Media Center Sandbox

Resources and discussion for developing experiences in the Windows Media Center platform.
Welcome to The Media Center Sandbox Sign in | Join | Help
in Search

How to create objects / set object properties in MCML

Last post 07-21-2006, 7:26 AM by Mark. 7 replies.
Sort Posts: Previous Next
  •  07-19-2006, 8:03 PM 171

    How to create objects / set object properties in MCML

    I am trying to create a C# object from the locals section of a MCML page. I have tried the following:

    <locals>

         <namespace:car Name="BMW" Year="1998"/>

    </Locals>

    The object's constructor takes an integer as parameter. The above does not work. When the page is displayed, MCE crashes and displays "PROGRAM NOT RESPONDING". The page works if the car object has a default constructor with no parameters. That is fine, but how to I set the property on the car object. The car object has a property int Year with a get/set. How do I call them from MCML? I tried the following:

    <rules>

    <default>

      <set Target="[BMW.Year]" Year="1998"/>

    </default>

    </rule>

    This also causes the dreaded "PROGRAM NOT RESPONDING". How do I set the property of the object. I can't figure it out. I have also tried <invoke>, with the same result. I have also tried to use a target of [BMW.set_Year], also with no results.

    Zakspeed

  •  07-20-2006, 12:24 AM 172 in reply to 171

    Re: How to create objects / set object properties in MCML

    Going from memory now, but try

    <locals>
       <namespace:car Name="BMW"/>
    </locals>

    and then

    <set Target="[BMW.Year]" Value="1998"/>

    Also, make sure car is defined as

    public sealed class car : ModelItem

    and you properties are public.  It's best to run through VS2005 rather than direct in the MCE shell, as VS2005 will run in MCMLpad which will give you error information instead of "Program Not Responding".

    Cheers,
    Andy

  •  07-20-2006, 7:33 AM 176 in reply to 171

    Re: How to create objects / set object properties in MCML

    zakspeed,

    MCML needs .NET objects that have parameterless constructors. Your initial route was correct. Doing:

    <n:car Name="BMW" Year="1998"/>

    will 1) create a car object, and 2) call the Year property setter with the value of 1998.

    I'm not sure what build you are using, but, even when running within MCE, you should still get info about what exactly happened. McmlPad is a good choice in this case when building up your UI. You typically make small changes and hit F5 over and over. Of course, it'll present parser errors (and runtime errors) without crashing (which is what is likely happening here).

    Make sure your property is public. Otherwise, if you don't want it public, you can use the [MarkupVisible] attribute on it so that the parser can access it and no one else can access it via code. It all depends on how you want to present your OM.

    - Mark


    Mark Finocchio (Microsoft)
  •  07-20-2006, 8:00 AM 178 in reply to 176

    Re: How to create objects / set object properties in MCML

    Mark,

      I am doing more than creating UI. I need the Add-In to be created because it creates a singleton object that keeps track of the program state. I am using Build 5384 Vista Beta 2. I am not able to get any runtime errors from within MCE even when debugging ehexthost.exe with Visual Studio. As soon as bad MCML is seen, MCE locks up with "Program not responding". I would like to use MCMLPad, but I can not since MCMLPad does not seem to setup the Add-In Completely. MCMLPad is a good tool, but having the entire MCE environment is key to developing the Add-Ins.

    Zakspeed

  •  07-20-2006, 10:13 AM 181 in reply to 176

    Re: How to create objects / set object properties in MCML

    Mark,

     It looks like the object is never created. I am debugging the Add-In and the constructor is never reached.

    Zakspeed

  •  07-20-2006, 10:22 AM 182 in reply to 178

    Re: How to create objects / set object properties in MCML

    Zakspeed,

    It really depends on your add-in. You don't need the "Lauch" callback in order to set up a singleton from just markup. You can take two approaches: 1) always use live data, or 2) set it up so that each individual page has test data that it can use. I actually prefer option #2 since it's a modular approach that makes it easy to make changes and move on.

    You can do something like this:

    <Mcml ...>

        <UI Name="MyPage">
           <Properties>
               ... data ...
           </Properties>
        </UI>

        <UI Name="MyPageTest">
           <Locals>
              ... test data ...
           </Locals>
           <Content>
               <me:MyPage Data="...test data..."/>
           </Content>
        </UI>

    </Mcml>

    When loading under McmlPad, you'd do: file://MyPage.mcml#MyPageTest to load your test for MyPage.

    So, if you were to create a Button, you'd use a test Command.

    I'd like to hear more about your scenario. What sort of info is in your singleton?


    Mark Finocchio (Microsoft)
  •  07-20-2006, 3:08 PM 184 in reply to 182

    Re: How to create objects / set object properties in MCML

    The singleton is a collection of C# objects generated from of COM objects. It talks to an out-of-proc server. I did not want to load the objects from this server all the time, so I created a wrapper class that keeps track of the object's Id. Doing so, I can reconnect to the out-of-proc server at any time (it does crash occasionally). I also did not want the pages to create and pass this singleton because the developers of the MCML pages will likely forget to pass it and the whole thing breaks. That is also why I created a GotoPage function on the singleton to navigate to pages. It automatically sets up the correct property (i.e. passing the singleton to the page).

    I guess I am going against the grain here. MCMLPad just does not do what I need, but it is the only game in town. I have been told several times that MCMLPad will run in MCE. I don't see how this is done and the documentation is lacking. If I can eventually get it to run in MCE, will it provide the Host and create my Add-In and start the Add-In like MCE will? I need all this for debugging. I make what seems like a small change and MCE hangs. It makes for a very bad development experience.

     

    Zakspeed

  •  07-21-2006, 7:26 AM 186 in reply to 184

    Re: How to create objects / set object properties in MCML

    I suggest passing through your singleton to all your pages and use <Navigate> to switch to new pages (other than doing it in code). To make sure this happen, make it a requirement that 1) all pages in your product derive from a base UI that has your singleton property on it (look for the "base UI" sample), and 2) make that property "$Required" (look for the "properties" sample). If you do all this, you'll get a nice parser error stating that you forgot to pass in that singleton through to the next page.

    McmlPad can run standalone or as an add-in. You must be using Beta 2, since these issues you struggling with have been fixed (no more lockups). When you install the SDK now, McmlPad is automatically registered under "Other Programs", and it is also made so that you get it from VS.NET MCML projects when you run (including parser errors within VS.NET's error window). You can RegisterMceApp McmlPad.xml from your eHome directory to get it runnable from MCE.


    Mark Finocchio (Microsoft)
View as RSS news feed in XML
Powered by Community Server, by Telligent Systems