Calling a method within the Model once the Screen has completed loading (1 Viewer)

Valk

Portal Pro
February 25, 2006
302
108
Australia Australia
I'm having a little trouble. I want to call a method after the Screen has fully loaded.

Reason been I'm going to call

var screenManager = ServiceRegistration.Get<IScreenManager>();

screenManager.ShowDialog("dialogWeatherSearchResult");

If certain conditions are met.

At the moment the best hack I can think of goes something along the lines of:

<ControlTemplate.Triggers>
<DataTrigger Binding="{Binding Loaded}" Value="False">
<!--<Command Source="{StaticResource Model}" Path="DetectLocation"/>-->
<Setter Property="{Binding Loaded}" Value="True"/>
</DataTrigger>
</ControlTemplate.Triggers>

Note the above doesn't work but the idea was to set a property and use that to trigger the function in the code behind (sharp learning curve with XAML at the moment).

I've been focusing of the XAML because I can't see a IWorkflowModel function that is called after the Screen has focus.

Any advice / thoughts would be appreciated.
 

Valk

Portal Pro
February 25, 2006
302
108
Australia Australia
In my quest I decided to dig deeper into MP2. As I was going through I came across IWorkflowModel.cs and noticed a small TODO:

// TODO: Create methods Activate and Deactivate to execute initialization/deinitialization like message queue setup etc.

// EnterModelContext and ExitModelContext can then be replaced by ChangeModelContext.

While I didn't implement ChangeModelContext I did add an void Activate(NavigationContext currentContext); function to IWorkflowModel.cs and implemented it in WorkflowManager.cs at the end of the function UpdateScreen_NeedsLock(bool push, bool force)

After that I found I was able to get my dialog to appear but while the thread is working on the first load of the form the side menu expands until the dialog is shown.

At the moment I'm not sure what's causing the menu to expand in the first place but it's causing me grief.

So I guess the follow up question is how did @Albert I guess intend the Activate function to work so I can do this properly? ;)
 

morpheus_xx

Lead Dev MP2
  • Team MediaPortal
  • March 24, 2007
    11,483
    7,015
    Germany Germany
    Country flag
    Hi @Valk,

    did you push your changes already, so I can take a look at it? I don't fully understand the problem yet.

    At the moment I'm not sure what's causing the menu to expand in the first place but it's causing me grief.
    Are you talking about Titanium skin? If you look at Titanium\screens\master_menu.xaml you'll find:
    XML:
    		  <Grid.Triggers>
    			<!-- Setting default state of menu to hidden -->
    			<EventTrigger RoutedEvent="Screen.Show">
    			  <TriggerCommand Command="{Command Source={StaticResource MenuModel}, Path=CloseMenu}"/>
    			</EventTrigger>
     
    			<!-- Slide-In animation when the MenuModel.ShowMenu gets true -->
    			<DataTrigger Binding="{Binding Source={StaticResource MenuModel},Path=IsMenuOpen}" Value="True">
    On "Screen.Show" event the "CloseMenu" is invoked, it will hide the menu. Hiding itself is done in DataTrigger.

    Morpheus
     

    Valk

    Portal Pro
    February 25, 2006
    302
    108
    Australia Australia
    Sorry I haven't pushed the latest version yet (I'll do it shortly).

    All I'm trying to do is call DetectLocation() when someone enters the weather.xaml screen.

    I looked over triggers but didn't find EventTrigger. That would do all I need looking at your example (I didn't read master_menu.xaml).

    That said I'm pretty sure I know why the menu is expanded after that code snippet you posted. I call Activate before

    WorkflowManagerMessaging.SendNavigationCompleteMessage();
    is called so the Event Trigger won't have happened yet. So I guess is that a good behaviour? The first quick solution I came up with was to call DetectLocation() Aysnc but I may even change it to an EventTrigger.
     

    Valk

    Portal Pro
    February 25, 2006
    302
    108
    Australia Australia
    Tried EventTrigger and it calls my trigger first so I get the same undesired effect if I call synchronously. If I make the call asynchronously I can get around the issue, it just means I have to make sure the context is still active or add a cancelation token before it shows any dialogs.

    Personally, I like the Activate call over using EventTrigger so for the moment I'll stick to using it.

    Only real issue remaining is the dialogs. The dialogs I wish to reuse are set to use the WeatherSetupModel instead of the WeatherModel, is there a way to make them support either Models or do I just have to copy them?

    Oh and I remembered to push the changes this time :D .
     
    Last edited:

    morpheus_xx

    Lead Dev MP2
  • Team MediaPortal
  • March 24, 2007
    11,483
    7,015
    Germany Germany
    Country flag
    I think detection of location is better placed inside WeatherSetupModel, so there should be no need to change the dialog's model reference.

    If reallllly required, you can access multiple models from screen, just add a <Model..> XAML resource definition and use it in binding accordingly. There are many examples in existing xaml pages.

    I will be away for the next week and can check code changes when I'm back.

    Thanks again for your work!
     

    Valk

    Portal Pro
    February 25, 2006
    302
    108
    Australia Australia
    The only reason I have it in the WeatherModel also is for the first time triggering. I guess the other way to do it would be automatically navigate to the setup screen if no settings are defined.

    Also thanks for the help.
     
    Last edited:

    Users Who Are Viewing This Thread (Users: 0, Guests: 1)

    Top Bottom