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

Invoke Command on page load

Last post 07-25-2010, 2:00 AM by win7-demon. 5 replies.
Sort Posts: Previous Next
  •  07-23-2010, 7:36 AM 9724

    Invoke Command on page load

    Hi, at first i thought i would use binding to update the UI in response to a button click but seems that any code is executed before the UI is updated, which means the updated UI isn't shown or is shown to late.

    So i created a new page which contains the updated UI, now when the page loads i want it to invoke a command in the code behind. I can invoke the command by adding a button but i'd like it to happen without the need to click the button.

    Any ideas as to how i can acheive this?

    Thanks

  •  07-24-2010, 11:15 AM 9725 in reply to 9724

    Re: Invoke Command on page load

    To invoke a command the first time your page is navigated to, put a bool property with a value of true in your code behind called "FirstRun" and check it in your rules. If true, set it to false then execute your command in your rule.

    If you want something to happen every time your page is navigated to, or navigated back to (i.e. backpage in the page stack - every time your page becomes visible), then put the bool property in the section rather than in your code behind.

    Cheers,
    Andrew
  •  07-24-2010, 4:16 PM 9726 in reply to 9725

    Re: Invoke Command on page load

    Thanks for the repy AndyC, not sure what i'm doing wrong.

    This is my code behind:

    private bool firstrun = true;

    public bool FirstRun

    {

    get

    {

    return firstrun;

    }

    set

    {

    firstrun = value;

    FirePropertyChanged("FirstRun");

    }

    }

    I'm using this in mcml:

    <Rule>

    <Conditions>

    <Equality Source="[Model.FirstRun]" Value="false" />

    </Conditions>

    <Actions>

    <Invoke InvokePolicy="AsynchronousNormal" Target="[Model.Tuner.Invoke]"/>

    </Actions>

    </Rule>

     

    At the moment page loads no command invoked, if i set to true command is invoked but the page doesn't load.

    Any ideas

    Thanks

  •  07-24-2010, 11:18 PM 9727 in reply to 9726

    Re: Invoke Command on page load

    You're checking FirstRun is false in your MCML - you want to check it's true!

    You also need to set FirstRun to false prior to your Invoke.

    Cheers,
    Andrew
  •  07-24-2010, 11:19 PM 9728 in reply to 9727

    Re: Invoke Command on page load

    Didn't read the other bit enough - if it's not loading the page, it most likely means that the code you're invoking has an issue.

    Cheers
    Andrew
  •  07-25-2010, 2:00 AM 9729 in reply to 9728

    Re: Invoke Command on page load

    Thanks again AndyC for your help.

    Edited post as although the command was invoked on the page load, somehow i lost any reference to mcstore, which is required by our app.

    So finally i now have this working, one of the key items was the InvokePolicy which had to be set to

    AsynchronousLowPri, set to any other and it wouldn't work.

    I also found having "Model" navigate to the page and setting the FirstRun value to true, overcome

    any issues with the code.

    Thanks

    If anyone needs an example, if having similar issues just ask and i'll post the code.
View as RSS news feed in XML
Powered by Community Server, by Telligent Systems