2

Problem is: Some UWP (C#) code works well on PC but DOESN'T work on Xbox One device.

I have two ListViews 'LeftListView' and 'RightListView'. Each list has event 'ItemClick'. If event is fired on LeftListView I move focus to RightListView and the similar happens when event is fired on RightListView.

    <ListView
        x:Name="LeftListView"
        Grid.Column="0"
        SelectedIndex="0"
        HorizontalAlignment="Center"
        VerticalAlignment="Center"
        IsItemClickEnabled="True"
        ItemClick="Left_ListView_ItemClick">
        <x:String>Left Item 1</x:String>
        <x:String>Left Item 2</x:String>
        <x:String>Left Item 3</x:String>
        <x:String>Left Item 4</x:String>
        <x:String>Left Item 5</x:String>
    </ListView>

    <ListView
        x:Name="RightListView"
        Grid.Column="1"
        SelectedIndex="0"
        HorizontalAlignment="Center"
        VerticalAlignment="Center"
        IsItemClickEnabled="True"
        ItemClick="Right_ListView_ItemClick">
        <x:String>Right Item 1</x:String>
        <x:String>Right Item 2</x:String>
        <x:String>Right Item 3</x:String>
        <x:String>Right Item 4</x:String>
        <x:String>Right Item 5</x:String>
    </ListView>

C# Code

private void Left_ListView_ItemClick(object sender, ItemClickEventArgs e)
{
    //Set focus to "Right ListView"
    GetFocusedItemContainer(RightListView).Focus(FocusState.Programmatic);
}

private void Right_ListView_ItemClick(object sender, ItemClickEventArgs e)
{
    //Set focus to "Left ListView"
    GetFocusedItemContainer(LeftListView).Focus(FocusState.Programmatic);
}

private ListViewItem GetFocusedItemContainer(ListView lv)
{
    return (ListViewItem)lv.ContainerFromIndex(lv.SelectedIndex);
}

My question is: Is it already known issue on Xbox? Is it defect on Xbox device only? Because this code works well on PC (Windows 10 Creators Update)

BTW: I have a solution which works well on Xbox too.

//!!! Solution which works on Xbox!!!
Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Low, 
    () => { GetFocusedItemContainer(LeftListView).Focus(FocusState.Programmatic); });

As you can see - solution is, but it looks like a temporary Work-Around.

  • What's the OS version on your XBOX? I created a 16299 project and used your code to test on my XBOX, it worked well. My XBOX OS version is 16299.4055. – Xie Steven Dec 11 '17 at 06:26
  • 1
    I use OS version 10.0.16299.4055 (rs3_release_xbox_dev_1711.171203-1700) Does it work without solution with Dispatcher? – Viacheslav D. Dec 11 '17 at 10:22
  • 1
    Here is a link to access Archive with project on Google Drive. https://drive.google.com/file/d/1VqywhN5vxoUK07-uAbkWz1YydmPl_96k/view?usp=sharing – Viacheslav D. Dec 11 '17 at 10:36
  • Your project code worked well on my side. My XBOX OS version is the same with you. – Xie Steven Dec 13 '17 at 07:10
  • It's at least strange that couple of devices on my side do not work. Let's clarify one more time: - Do you press 'A' on GamePad to move focus? - Or do you use Left/Right button to move focus? – Viacheslav D. Dec 18 '17 at 11:46
  • I used Left/Right button to move focus and press 'A' to select one item to fire the `ItemClick` event. – Xie Steven Dec 21 '17 at 05:54
  • Excuse me @XavierXie-MSFT but your answer is not full and something still stay unclear for me. 1) When you press Left/Right - it should work, focus moves from one list to another (it works like on my Xbox) - this case works perfectly. 2) But if to press 'A' - focus DOES NOT move from one list to another list - that is a problem. Yes, ItemClick is fired - but focus does not move like it works with Left/Right. There is an implementation of focus moving inside 'ItemClick' which should work but don't. Question: Does pressing 'A' on your Xbox moves focus from one list to another? – Viacheslav D. Dec 22 '17 at 07:41
  • I'm also a little confused about your operation. When you pressed 'A' button on GamePad, it will select one item in ListView, then ItemClick event will be fired. In ItemClick event handler method, you make another listvciew get focused. There's no problem. I monitored the return value of `Control.Focus()` to judgement if the control has got focused successfully. – Xie Steven Dec 25 '17 at 06:51
  • @XavierXie-MSFT we're closer to right solution. I'm more than sure that you did not understand question. Purpose of my code "to move focus from list to list NOT BY PRESSING Left/Right, I want to move focus programmatically when 'ItemClick' is fired". Please do not use Left/Right buttons, focus should move when user clicks 'A' button. – Viacheslav D. Dec 26 '17 at 09:25
  • Maybe, you could provide a [mcve] and record a video to show your operation that will help me understand your question. – Xie Steven Dec 26 '17 at 09:53

0 Answers0