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

Scroll Home without focusing on scroller

Last post 02-20-2010, 3:56 PM by soultaker. 11 replies.
Sort Posts: Previous Next
  •  02-08-2010, 3:40 AM 9539

    Scroll Home without focusing on scroller

    Hi,

    Really simple question, I wish to invoke a scroll to the first item within a scroller (ie. scroll.home) without the focus moving to the scroller object. How do I do this elegantly?

    My current solution is really complicated and confusing myself after a few months of not looking at it.
    blog.manghera.com
  •  02-10-2010, 7:01 AM 9540 in reply to 9539

    Re: Scroll Home without focusing on scroller

    Never found a way to do that unfortunately - the best I've come up with is setting focus to the scroller, then setting focus back to the previous item using a very short, async timer.

    Cheers,
    Andrew
  •  02-12-2010, 4:38 AM 9541 in reply to 9540

    Re: Scroll Home without focusing on scroller

    Aww man ... far too many hacks for simple things. Appreciate the feedback and knowing I'm not the only one with this problem.
    blog.manghera.com
  •  02-13-2010, 9:25 AM 9543 in reply to 9541

    Re: Scroll Home without focusing on scroller

    Personally I create an AreaOfInterestLayoutInput named "Focus" and do a SetLayoutInput on the UI element I want scrolled in view (but not in focus). This is a reflection HACK for a bit of functionality (AreaOfInterestLayoutInput) eHome uses to do this.
  •  02-14-2010, 10:19 AM 9547 in reply to 9543

    Re: Scroll Home without focusing on scroller

    Have you got a code sample for that David?

    Cheers,
    Andrew
  •  02-15-2010, 9:21 AM 9551 in reply to 9547

    Re: Scroll Home without focusing on scroller

    Gotta pull it out of an existing project. I'll try and put something together tonight.
  •  02-15-2010, 8:56 PM 9554 in reply to 9551

    Re: Scroll Home without focusing on scroller

    I haven't had enough time to put together a real slick sample but I do have an illustration (http://cid-dafd19bc5d669d8f.skydrive.live.com/browse.aspx/AreaOfInterestLayoutInput). I use this code for things like pivots and slidedecks as a replacement for code like the following;

    <AreaOfInterestLayoutInput Name="AreaOfInterest" Id="Selected"/>

    ...

    <Rule>
            <Conditions>
              <Equality Source="[SlideDeck.ChosenIndex]" Value="[Index.SourceValue!cor:Int32]" />
            </Conditions>
            <Actions>
              <Invoke Target="[TextSlideName.SetLayoutInput]" oNewValue="[AreaOfInterest]" InvokePolicy="Synchronous"/>
              <Set Target="[TextSlideName.Font]" Value="[SelectedFont]"/>
              <Set Target="[TextSlideName.Margins]" Value="[SelectedItemMargins]"/>
              <Set Target="[TextSlideName.Alpha]" Value="1.0"/>
            </Actions>
          </Rule>
          <Rule>
            <Conditions>
              <Equality Source="[SlideDeck.ChosenIndex]" Value="[Index.SourceValue!cor:Int32]" ConditionOp="NotEquals" />
            </Conditions>
            <Actions>
              <Invoke Target="[TextSlideName.SetLayoutInput]" idInput="[AreaOfInterest!ILayoutData.Data]" oNewValue="null" InvokePolicy="Synchronous"/>
              <Set Target="[TextSlideName.Font]" Value="[Font]"/>
            </Actions>
          </Rule>

    What is going on in the above markup (Microsoft.MediaCenter.Shell.dll!SlideAnimations.mcml) is when the user navigates right or left in a SlideDeck the scroller with the slide titles never gets selected or focus, but "slides" into place as the selected title.

    When looking at my markup in Default2.mcml the two things to pay attention to are the wireup of the AreaOfInterestHelper;

    <shl:AreaOfInterestHelper Name="AreaOfInterestHelper"/>

    And how to use it;

    <Invoke Target="[AreaOfInterestHelper.SetSelected]" Panel="[LabelPanel]"/>
    <!--Invoke Target="[AreaOfInterestHelper.SetFocused]" Panel="[LabelPanel]"/-->
    <!--Invoke Target="[AreaOfInterestHelper.RemoveLayoutInput]" Panel="[LabelPanel]"/-->

    The code behind for this does the following;

    public void SetSelected(object Panel)
            {
                Type panelType = Panel.GetType();
                areaOfInterestWrapper = new PrivateObjectReflector("Microsoft.MediaCenter.UI.AreaOfInterestLayoutInput, Microsoft.MediaCenter.UI, Version=6.0.6000.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35", new object[] { "Selected" });
                MethodInfo theMethod = panelType.GetMethod("SetLayoutInput", new Type[] { areaOfInterestWrapper.Instance.GetType() });
                theMethod.Invoke(Panel, new object[] { areaOfInterestWrapper.Instance });
            }

    Notice how I'm setting the id of the AreaOfInterestLayoutInput to "Selected". You can set a UI element to selected or focused and trick the scroller. If you want to remove this you would "RemoveLayoutInput" with the same logic as the MS SlideDeck example above.

    Code should be pretty self explanatory.

    If I get time I'll put it into a proper sample illustration, but you should get the gist.

  •  02-20-2010, 4:40 AM 9556 in reply to 9554

    Re: Scroll Home without focusing on scroller

    Hi David,

    Thats really nice and clean. Is it ok for me to use this in my open source project? I've tested it out and it seems to be working really nicely.

    Thanks.

    - Jas
    blog.manghera.com
  •  02-20-2010, 8:17 AM 9557 in reply to 9556

    Re: Scroll Home without focusing on scroller

    Yes, I posted it to help you. Besides-this is in the skin I committed to implement for your project :)

    There are also a few others that I have had to implement along these same lines. For example you can do a ForceRefresh through reflection on a Repeater if you want to invalidate it and dynamically do a content switch;

    <!-- If the ContentItemTemplate changes, all our repeated content is invalid.  Re-repeat everything. -->
          <Rule>
            <Conditions>
              <Equality Source="[Model.ContentItemTemplate]" ConditionOp="NotEquals" Value="null"/>
              <Modified Source="[Model.ContentItemTemplate]" />
            </Conditions>
            <Actions>
              <Set Target="[Repeater.ContentName]" Value="[Model.ContentItemTemplate]"/>
              <Invoke Target="[RepeaterHelper.ForceRefresh]" Repeater="[Repeater]"/>
            </Actions>
          </Rule>

     

  •  02-20-2010, 11:38 AM 9559 in reply to 9557

    Re: Scroll Home without focusing on scroller

    Thats interesting, what is the purpose of ForceRefresh? Obviously it doesn't scroll the items back to the home as that is needed to be done on the scroller. Which situation do you find it necessary to use a ForceRefresh on the Repeater?
    blog.manghera.com
  •  02-20-2010, 1:34 PM 9560 in reply to 9559

    Re: Scroll Home without focusing on scroller

    I use it if I want to change the content template used for the items in a Repeater. Say I want to switch my items from a list view to a grouped poster view. I can change the template used and trigger a ForceRefresh on the Repeater to take care of everything else. The selected item in the repeater is maintained and all other UI elements driven by the repeated items template are then rebound.
  •  02-20-2010, 3:56 PM 9561 in reply to 9560

    Re: Scroll Home without focusing on scroller

    Very cool, I didn't even think that was possible.
    blog.manghera.com
View as RSS news feed in XML
Powered by Community Server, by Telligent Systems